拥有以下代码:
$oauth_nonce = md5(uniqid(rand(), true));
$oauth_timestamp = time();
$users_ids = implode(',',$users_ids['ids']);
$url = 'https://api.twitter.com/1.1/users/lookup.json';
$oauth_sig_text = self::sign_twitter($url,$oauth_token,false,$oauth_nonce,$oauth_timestamp,$users_ids);
$key = __TWITTERSECRET__ . '&' . $oauth_token_secret;
$signature = base64_encode(hash_hmac("sha1", $oauth_sig_text, $key, true));
$params = array(
'oauth_consumer_key' => __TWITTERKEY__,
'oauth_nonce' => $oauth_nonce,
'oauth_signature' => $signature,
'oauth_signature_method' => "HMAC-SHA1",
'oauth_timestamp' => $oauth_timestamp,
'oauth_token' => urlencode($oauth_token),
'oauth_version' => '1.0',
'user_id' => $users_ids
);
$url .= '?'.http_build_query($params);
$users_data = json_decode(file_get_contents($url),true);
echo '<pre>';
print_r($users_data);
echo '</pre>';
And signature:
protected function sign_twitter($url,$token,$verifier,$nonce,$timestamp,$ids=false){
$oauth_base_text = "GET&";
$oauth_base_text .= urlencode($url).'&';
$oauth_base_text .= urlencode('oauth_consumer_key='.__TWITTERKEY__.'&');
$oauth_base_text .= urlencode('oauth_nonce='.$nonce.'&');
$oauth_base_text .= urlencode('oauth_signature_method=HMAC-SHA1&');
$oauth_base_text .= urlencode('oauth_timestamp='.$timestamp."&");
$oauth_base_text .= urlencode('oauth_token='.$token."&");
$oauth_base_text .= urlencode('oauth_version=1.0&');
if ($verifier) {
$oauth_base_text .= urlencode("oauth_verifier=".$verifier."&");
$oauth_base_text .= urlencode("oauth_callback=".urlencode(__REDIRECT__)."&");
} else {
$oauth_base_text .= urlencode('user_id=' . $ids);
}
return $oauth_base_text;
}
I receive an error:
Array([errors] => Array([0] => Array([message] => Could not authenticate you [code] => 32)))
if you take a single identifier, the data are given ($users_ids = $users_ids['ids']['0']).
I have read a lot of topics on this issue, and everywhere it is written that the problem in comma that it should be encoded% 2C but it does not help ...
final url:
https://api.twitter.com/1.1/users/lookup.json?oauth_consumer_key=Q6KMZzN7AAW******HoxmA&oauth_nonce=ab7e09e8466e0c9893acf3da32de9565&oauth_signature=rhUPhe1HgfcR%2Fr3nkTomuksWPzo%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1378367650&oauth_token=1727480588-IlvYrJZcRnp3dKScJiyZfEEMRpiqlVMTQTr764Q&oauth_version=1.0&user_id=93456690%2C81866717
signature:
$oauth_nonce = md5(uniqid(rand(), true));
$oauth_timestamp = time();
$users_ids = implode(',',$users_ids['ids']);
$url = 'https://api.twitter.com/1.1/users/lookup.json';
$oauth_sig_text = self::sign_twitter($url,$oauth_token,false,$oauth_nonce,$oauth_timestamp,$users_ids);
$key = __TWITTERSECRET__ . '&' . $oauth_token_secret;
$signature = base64_encode(hash_hmac("sha1", $oauth_sig_text, $key, true));
$params = array(
'oauth_consumer_key' => __TWITTERKEY__,
'oauth_nonce' => $oauth_nonce,
'oauth_signature' => $signature,
'oauth_signature_method' => "HMAC-SHA1",
'oauth_timestamp' => $oauth_timestamp,
'oauth_token' => urlencode($oauth_token),
'oauth_version' => '1.0',
'user_id' => $users_ids
);
$url .= '?'.http_build_query($params);
$users_data = json_decode(file_get_contents($url),true);
echo '<pre>';
print_r($users_data);
echo '</pre>';
刚试过POST请求,没有帮助,所有完全相同的错误。
答案 0 :(得分:0)
重新生成Authtoken并使用新的Authtoken并再次检查。
答案 1 :(得分:0)
我正在关注official documentation来构建签名,我正在为每个错误的请求添加include_entities
。我删除它然后一切正常。