PHP version of curl command

Ask questions related to the eHive application programming interfaces, including the OAI-PMH data harvester, REST API and WordPress plugins.
karan.kumar
Posts: 5
Joined: Tue Aug 09, 2016 2:40 pm

PHP version of curl command

Postby karan.kumar » Tue Aug 09, 2016 3:17 pm

Hi,

I have been trying make curl command work in PHP but no luck. Could anyone help me out where I'm going wrong

$endpoint = "https://ehive.com/api/oauth2/v2/authorize";

$header[] = "Content-Type: application/x-www-form-urlencoded" ;
$header[]= "Client-Id: ....5056";
$header[] = "Client-Secret: ....4eab";
$header[] = "Authorization: OAuth";
$header[] = "Grant-Type: client_credentials";


$curl = curl_init($endpoint);

curl_setopt($curl, CURLOPT_HEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);


$json_response = curl_exec($curl);

karan.kumar
Posts: 5
Joined: Tue Aug 09, 2016 2:40 pm

Re: PHP version of curl command

Postby karan.kumar » Tue Aug 09, 2016 4:50 pm

Sorry Folks...It was me being nube.
Had to pass empty array as Post fields. So in case someone needs it in future

curl
-v
-H "Content-Type: application/x-www-form-urlencoded"
-H "Client-Id: <your clientId>"
-H "Client-Secret: <your clientSecret>"
-H "Authorization: OAuth"
-H "Grant-Type: client_credentials"
-X POST https://ehive.com/api/oauth2/v2/authorize

will look like this in php

$endpoint = 'https://ehive.com/api/oauth2/v2/authorize';
$header[] ='Content-Type:application/x-www-form-urlencoded';
$header[]='Client-Id:...5056';
$header[]='Client-Secret:...4eab';
$header[]='Authorization:OAuth';
$header[]='Grant-Type:client_credentials';
$postData = array();

$curl = curl_init($endpoint);

curl_setopt($curl, CURLOPT_HEADER, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postData);

$json_response = curl_exec($curl);


Return to “Developers”

Who is online

Users browsing this forum: No registered users and 1 guest