【发布时间】:2015-11-04 16:17:15
【问题描述】:
我正在尝试使用 Twitter 开发网站上的示例,但似乎无法获得与它们相同的签名。
我正在尝试在 https://dev.twitter.com/docs/auth/implementing-sign-twitter 上完成第 3 步,因为我收到“无效或过期令牌”错误,但我知道这不是因为我刚刚获得它,所以它一定有问题我的数据包。
我用来尝试生成它的代码是:
// testing bit
$oauth = array(
'oauth_consumer_key'=>'cChZNFj6T5R0TigYB9yd1w',
'oauth_nonce'=>'a9900fe68e2573b27a37f10fbad6a755',
'oauth_signature_method'=>'HMAC-SHA1',
'oauth_timestamp'=>'1318467427',
'oauth_token'=>'NPcudxy0yU5T3tBzho7iCotZ3cnetKwcTIRlX0iwRl0',
'oauth_version'=>'1.0'
);
$this->o_secret = 'LswwdoUaIvS8ltyTt5jkRh4J50vUPVVHtR2YPi5kE';
$this->c_secret = 'kAcSOqF21Fu85e7zjz7ZN2U4ZRhfV3WpwPAoE3Z7kBw';
ksort($oauth);
$string = rawurlencode(http_build_query($oauth));
$new_string = strtoupper($http_method).'&'.rawurlencode($main_url[0]).'&'.$string;
// The request_token request doesn't need a o_secret because it doesn't have one!
$sign_key = strstr($fullurl,'request_token') ? $this->c_secret.'&' : $this->c_secret.'&'.$this->o_secret;
echo urlencode(base64_encode(hash_hmac('sha1',$new_string,$sign_key,true)));exit;
我假设此页面上列出的键实际上是正确的:https://dev.twitter.com/docs/auth/creating-signature。所以在这种情况下,签名应该是 39cipBtIOHEEnybAR4sATQTpl2I%3D。
如果你能发现我遗漏的东西,那就太好了。
【问题讨论】:
-
我认为您不应该公开分享您的
*_secret令牌。它们是秘密是有原因的。 -
谢谢 - 这些不是来自 Twitter 官方网站。我试图复制他们的例子,看看我做错了什么。
标签: php twitter twitter-oauth