Domanda

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

È stato utile?

Soluzione

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);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top