doukan4795 2012-11-13 08:20
浏览 90
已采纳

inmobi API使用示例

I have to develop an application to interact the inmobi API. I have try some code but failed. Please help me how to use the API.

Its API docs URL is http://developer.inmobi.com/wiki/index.php?title=API_Guide_for_Onboarding_Publishers#API_Key

I am trying to create session for which I need to send the values in header. I have try the following code with post data and header as well but failed. did not get required output.

$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);

If I have the problem with the way then please suggest some suitable method for it. Many Thanks

  • 写回答

1条回答 默认 最新

  • doupeng5320 2012-11-20 21:28
    关注

    There are two problems in your code:

    1) The method of "https://api-sandbox.inmobi.com/v1.0/generatesession/generate" is not POST, it's a GET method

    2) CURLOPT_HTTPHEADER is expecting an array, not a key-value pair.

    Sample Code:

    $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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。