Php tmhOAuth无法验证oauth签名和令牌
我试图使用Matt Harris的oAuth php库从我的应用程序上的Twitter用户那里获取用户访问令牌,但我不断收到错误“验证oAuth签名和令牌失败” 具体地说,我正试图使用他的OAuth流教程的一个稍加修改的版本来获取它们的令牌,并将它们存储在我的数据库中,而不是会话中。 错误总是发生在此处的请求令牌函数中Php tmhOAuth无法验证oauth签名和令牌,php,twitter-oauth,http-status-code-401,Php,Twitter Oauth,Http Status Code 401,我试图使用Matt Harris的oAuth php库从我的应用程序上的Twitter用户那里获取用户访问令牌,但我不断收到错误“验证oAuth签名和令牌失败” 具体地说,我正试图使用他的OAuth流教程的一个稍加修改的版本来获取它们的令牌,并将它们存储在我的数据库中,而不是会话中。 错误总是发生在此处的请求令牌函数中 function request_token($tmhOAuth) { $code = $tmhOAuth->request( 'POST',
function request_token($tmhOAuth) {
$code = $tmhOAuth->request(
'POST',
$tmhOAuth->url('oauth/request_token', ''),
array(
'oauth_callback' => tmhUtilities::php_self()
)
);
if ($code == 200) {
$_SESSION['oauth'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
authorize($tmhOAuth);
} else {
outputError($tmhOAuth);
}
}
我已经检查了服务器时间,我知道它在格林尼治标准时间的5秒内。一位推特开发者说,时间应该在他们服务器的5分钟之内,所以我应该没事
我还检查了cacert.pem
文件是否与其他文件位于同一位置,即CURL期望的位置,并且我已关闭了“use\u ssl”和“CURL\u ssl\u verifypeer”选项,因为我的站点当前未设置ssl证书
以下是返回的响应对象:
["response"]=> array(6) {
["headers"]=> array(16) {
["date"]=> string(29) "Sat, 25 Aug 2012 16:38:24 GMT"
["status"]=> string(16) "401 Unauthorized"
["x_frame_options"]=> string(10) "SAMEORIGIN"
["x_mid"]=> string(40) "4147a367997b7a5221cbcd8446652b1ebc00230d"
["last_modified"]=> string(29) "Sat, 25 Aug 2012 16:38:24 GMT"
["content_type"]=> string(24) "text/html; charset=utf-8"
["expires"]=> string(29) "Tue, 31 Mar 1981 05:00:00 GMT"
["cache_control"]=> string(62) "no-cache, no-store, must-revalidate, pre-check=0, post-check=0"
["x_runtime"]=> string(7) "0.01766"
["pragma"]=> string(8) "no-cache"
["x_transaction"]=> string(16) "b8ffe07df233ba05"
["set_cookie"]=> string(265) "_twitter_sess=ginormous session id; domain=.twitter.com; path=/; HttpOnly"
["vary"]=> string(15) "Accept-Encoding"
["content_encoding"]=> string(4) "gzip"
["content_length"]=> string(2) "62"
["server"]=> string(3) "tfe"
}
["code"]=> int(401)
["response"]=> string(44) "Failed to validate oauth signature and token"
["info"]=> array(23) {
["url"]=> string(42) "http://api.twitter.com/oauth/request_token"
["content_type"]=> string(24) "text/html; charset=utf-8"
["http_code"]=> int(401) ["header_size"]=> int(1030)
["request_size"]=> int(498) ["filetime"]=> int(-1)
["ssl_verify_result"]=> int(0)
["redirect_count"]=> int(0)
["total_time"]=> float(0.265656)
["namelookup_time"]=> float(0.062211)
["connect_time"]=> float(0.139025)
["pretransfer_time"]=> float(0.139028)
["size_upload"]=> float(0)
["size_download"]=> float(62)
["speed_download"]=> float(233)
["speed_upload"]=> float(0)
["download_content_length"]=> float(62)
["upload_content_length"]=> float(-1)
["starttransfer_time"]=> float(0.265504)
["redirect_time"]=> float(0)
["certinfo"]=> array(0) { }
["redirect_url"]=> string(0) ""
["request_header"]=> string(498) "POST /oauth/request_token HTTP/1.1 User-Agent: tmhOAuth 0.621-SSL - //github.com/themattharris/tmhOAuth Host: api.twitter.com Accept: */* Accept-Encoding: deflate, gzip Authorization: OAuth oauth_callback="http%3A%2F%2Fcompleteset.us%2Fsettings%2Ftwitterlink", oauth_consumer_key="consumer_key", oauth_nonce="nonce", oauth_signature="sig", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1345912704", oauth_version="1.0" "
}
["error"]=> string(0) ""
["errno"]=> int(0)
}
我注意到,在将“use_ssl”设置为false之前,响应中的headers数组并不存在。我不知道这意味着什么,也不知道它是否有用,但我想我还是把它扔出去吧
如果您需要任何其他部分,我也会将tmhOAuth对象的其余部分全部转储。我花了太多时间试图使其正常工作,但从未从他的作者那里得到答案:(因此,我不得不切换到ZendFramework的OAuth模块。我希望你能找到能够帮助你的人。我很久没有回顾zend文档了,我忘了它甚至还有OAuth。我必须检查一下。谢谢你提醒我。你看了吗?出于某种原因,zend没有提供任何示例获取令牌字符串的难度很大,只有令牌对象。我只是想通过尝试使用token\u访问类的
toQueryString()
函数,而不仅仅是去它的父类并使用访问器,让事情变得更困难。