Suneth Kalhara Suneth Kalhara - 2 months ago 32
PHP Question

PHP execute curl Oauth

I want to send the following header using curl:

curl -H 'Authorization: OAuth oauth_signature_method="PLAINTEXT",⤦
⤥oauth_consumer_key="xxx",oauth_token="xxx",oauth_signature="xxx"' ⤦
⤥'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo/recent⤦
⤥?xn_pretty=true&fields=image.url,title&count=2'


Above command is for command line usage. Anyone know how to execute this using PHP curl?

Answer

The -H from curl command-line is CURLOPT_HTTPHEADER in PHP curl curl_setopt.

This should be the most basic example for what you need:

$auth = 'Authorization: YOUR_KEYS';
$url  = 'https://external.ningapis.com/xn/rest/apiexample/1.0/Photo/recent?xn_pretty=true&fields=image.url,title&count=2';

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array($auth));
curl_exec($ch);
curl_close($ch);