我正在创建一个OAuth库,并且遇到了Twitter实现的问题。虽然我已经为Flickr工作,并且正在返回正确的访问权限和密钥,但当我向Twitter API请求获取信息时,我收到了模糊的代码32:“无法验证您”。
有人可以查看下面的代码,并指出哪里出错了?如前所述,我认为必须是这一步,因为其他步骤与flickr相同并且工作正常,但这一步骤的处理方式不同:
$oauth = array('oauth_consumer_key' => 'key',
'oauth_signature_method' => 'HMAC-SHA1',
'oauth_timestamp' => 1415633132,
'oauth_nonce' => 1817099296,
'oauth_version' => '1.0',
'oauth_token' => 'token',
'oauth_signature' => 'signature'
);
function buildAuthorizationHeader($oauth){
$r = 'Authorization: OAuth ';
$values = array(); //temporary key=value array
foreach($oauth as $key=>$value)
$values[] = "$key=\"" . rawurlencode($value) . "\"";
$r .= implode(',', $values);
return $r;
}
function sendRequest($oauth){
$header = array( buildAuthorizationHeader($oauth), 'Expect:');
$options = array(CURLOPT_HTTPHEADER => $header,
CURLOPT_HEADER => false,
CURLOPT_URL => 'https://api.twitter.com/1.1/search/tweets.json?q=london',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false);
$ch = curl_init();
curl_setopt_array($ch, $options);
$response = curl_exec($ch);
curl_close($ch);
return $response;
}