我正在使用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
答案 0 :(得分:0)
我找到了正确的答案
$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);