【发布时间】:2018-03-14 17:46:31
【问题描述】:
- 我正在尝试访问具有 OAuth1.0 的 api。
- 问题是当我尝试使用 Postman 时,我得到了响应,但使用 PHP curl 时会出现错误。
-
在邮递员中我传递参数如下
url='xxxx', Authentication stuff is type=OAuth1.0,Consumer Key,Consumer Secret, Token, Token Secret, Timestamp, Nonce, Version=1.0, Realm=Optional
以下是我尝试过的代码
$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,因为存在认证问题。现在我从 api curl 错误 403 得到“拒绝访问”,因为我通过 curl 传递 Oauth 1.0 的方式有问题。
- 这是我第一次尝试使用 curl 的 outh1.0。请帮助我在我的代码中发生了什么。我试过使用this link
【问题讨论】:
-
我确定有a PHP library 可以做到这一点。
-
你能给我举个例子吗