OAuth1.0与php和CURL无法正常工作

时间:2016-10-05 07:34:04

标签: php curl oauth

  • 我正在尝试点击具有OAuth1.0的api。
  • 问题是,当我尝试使用Postman时,我得到了回复,但是PHP卷曲了它的错误。
  • 在邮递员中,我传递的参数如下

    url =' xxxx',身份验证内容为type = OAuth1.0,Consumer Key,Consumer Secret,Token,Token Secret,Timestamp,Nonce,Version = 1.0,Realm = Optional

    < / LI>
  • 以下是我试过的代码

$url="xxx";
$header[]         = 'Content-Type: application/x-www-form-urlencoded';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_HTTPHEADER,     $header);
curl_setopt($ch, CURLOPT_POST,        true);
curl_setopt($ch, CURLOPT_POSTFIELDS, urlencode('Authorization:OAuth oauth_consumer_key="xxx",oauth_token="xxx",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1475651061",oauth_nonce="LyA5sR",oauth_version="1.0",oauth_signature="xxx"'));
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
if(curl_error($ch))
{
echo 'error:' . curl_error($ch);
}
echo "<pre>";print_r($result);exit;
  • 我添加了CURLOPT_SSL_VERIFYPEER,因为存在认证问题。现在我得到了“拒绝访问”#39;来自api curl错误403,因为我通过curl传递给Oauth 1.0的方式有问题。
  • 这是我第一次尝试使用curl outh1.0。请帮我解释一下我的代码。我尝试过使用this link

2 个答案:

答案 0 :(得分:0)

你使用的是错误的做法。请查看此文章

http://developer.gettyimages.com/forum/read/184531

答案 1 :(得分:0)

问题在于oauth签名没有正确形成。您可以参考https://oauth.net/core/1.0/以获得更清晰