我必须开发一个应用程序来与inmobi API交互。我尝试了一些代码,但失败了。请告诉我API的使用方法。
其API docs URL为http://developer.inmobi.com/wiki/index.php?title=API_Guide_for_Onboarding_Publishers#API_Key
我正在尝试创建会话,我需要在标头中为其发送值。我也尝试了以下带有post数据和标题的代码,但失败了。未获得所需的输出。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-sandbox.inmobi.com/v1.0/generatesession/generate");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array(
'username' => 'xxxxxxx',
'password' => 'xxxxx',
'secretKey' => 'xxxx',
'Content-type'=> 'application/json'
);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo "<pre>";
print_r( $info);如果我有问题的方式,那么请建议一些合适的方法。非常感谢
发布于 2012-11-21 05:28:27
您的代码中有两个问题:
1) "https://api-sandbox.inmobi.com/v1.0/generatesession/generate“的方法不是POST,而是GET方法
2) CURLOPT_HTTPHEADER需要一个数组,而不是键值对。
示例代码:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api-sandbox.inmobi.com/v1.0/generatesession/generate");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, truea);
$data = array(
'username: XXXXXXXX',
'password: XXXXXXXX',
'secretKey: XXXXXXXXXXXXXXX'
);
//curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_HTTPHEADER, $data);
$output = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo "<pre>";
print_r( $info);
print_r($output);https://stackoverflow.com/questions/13357455
复制相似问题