如何将 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 示例
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 之后 google 做了这个,但它对我不起作用。
// 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);
我正在使用 https://apptweak.io api, 他们在他们的代码示例中没有提到 PHP 示例...
请告诉我,如何理解和编写 Curl API 示例到 PHP curl
这是简单的 "appteak.com" curl 示例
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 之后 google 做了这个,但它对我不起作用。
// 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);