PHP execute curl Oauth

拥有回忆 提交于 2019-12-24 18:21:35

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/12071420/php-execute-curl-oauth

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!