繁体   English   中英

如何将 Curl api 示例写入 PHP curl

[英]How to write Curl api example into PHP curl

我正在使用https://apptweak.io api,他们没有在他们的代码示例中提到 PHP 示例......

请告诉我,如何理解 Curl API 示例并将其写入 PHP curl

这是简单的“appteak.com”卷曲示例

curl -G https://api.apptweak.com/ios/applications/284993459/informations.json \
-d country=us \
-d language=en \
-d device=iphone \
-H "X-Apptweak-Key: my_api_key"

这是另一个例子

$ curl -H "X-Apptweak-Key: my_api_key" \
https://api.apptweak.com/android/applications/com.facebook.katana.json?country=be&language=nl

如何在 PHP 中编写这些 curl?

我在 php 中做了这个,在谷歌之后,但它对我不起作用。

// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'https://api.apptweak.com/android/applications/com.facebook.katana.json?country=be&language=nl',
   // CURLOPT_USERAGENT => 'Codular Sample cURL Request',
    CURLOPT_POST => 1,
    CURLOPT_POSTFIELDS => array(
        'X-Apptweak-Key' => "my_api_key",
    )
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);


var_dump($resp ); //return false

我找到正确答案

$token = "my_api_key";
$url = "http://URL.com";

$options = array('http' => array(
    'header' => array("X-Apptweak-Key: $token"),
));
$context = stream_context_create($options);

$result = file_get_contents($url, 0, $context);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM