我正在尝试使用php和tmhOAuth开发一个twitter应用程序
我正在使用此代码来获取访问令牌。此代码在我的测试服务器中工作,但不在生产服务器中。两台服务器的php配置几乎相同。
if(isset($_REQUEST['oauth_verifier'])) {
$tmhOAuth->config['user_token'] = $_SESSION['oauth']['oauth_token'];
$tmhOAuth->config['user_secret'] = $_SESSION['oauth']['oauth_token_secret'];
$code = $tmhOAuth->request('POST', $tmhOAuth->url('oauth/access_token', ''), array(
'oauth_verifier' => $_REQUEST['oauth_verifier']
));
if ($code == 200) {
$_SESSION['access_token'] = $tmhOAuth->extract_params($tmhOAuth->response['response']);
unset($_SESSION['oauth']);
header("Location: {$here}");
} else {
outputError($tmhOAuth);
}
}
我的推特回复空[回复] => 。
至少我应该收到一条错误消息。请有人能告诉我什么是错的吗?
tmhOAuth Object
(
[params] => Array
(
)
[headers] => Array
(
[Authorization] => OAuth oauth_consumer_key="htxmSKEwkd5jPB6z1bQI6Q", oauth_nonce="adb19fb2bc5f76060b63bcbb1b3e2b94", oauth_signature="E5Vb62A00L8Nj8uyt9MRKdFk6ck%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1329438683", oauth_token="g3ekXAg9SwoYIge2l1E6JGwIQ02QYiha8uz5TMVA", oauth_verifier="vOrM6QWwGRpTEWgE2Kk2Y87DL1mlx324r4wh2SsUo", oauth_version="1.0"
[Content-Type] =>
[Content-Length] =>
[Expect] =>
)
[auto_fixed_time] =>
[buffer] =>
[config] => Array
(
[user_agent] => tmhOAuth 0.61+SSL - //github.com/themattharris/tmhOAuth
[use_ssl] => 1
[host] => api.twitter.com
[consumer_key] => htxmSKEwkd5jPB6z1bQI6Q
[consumer_secret] => fmNsDdu809uAARz0EslIL5Tj9m3XxLuaTVg6RSVnAQ
[user_token] => g3ekXAg9SwoYIge2l1E6JGwIQ02QYiha8uz5TMVA
[user_secret] => 4K8chxSWwwQ5nk1HSQrrbNW23FIGWiNLMycoqqxUV0
[force_nonce] =>
[nonce] => adb19fb2bc5f76060b63bcbb1b3e2b94
[force_timestamp] =>
[timestamp] => 1329438683
[oauth_version] => 1.0
[oauth_signature_method] => HMAC-SHA1
[curl_connecttimeout] => 30
[curl_timeout] => 10
[curl_ssl_verifyhost] => 2
[curl_ssl_verifypeer] => 1
[curl_cainfo] => /home/content/00/6684400/html/html-tweetcomments/to/cacert.pem
[curl_capath] => /home/content/00/6684400/html/html-tweetcomments/to
[curl_followlocation] =>
[curl_proxy] =>
[curl_proxyuserpwd] =>
[curl_encoding] =>
[is_streaming] =>
[streaming_eol] =>
[streaming_metrics_interval] => 60
[as_header] => 1
[debug] =>
[multipart] =>
)
[method] => POST
[url] => https://api.twitter.com/oauth/access_token
[signing_params] => oauth_consumer_key=htxmSKEwkd5jPB6z1bQI6Q&oauth_nonce=adb19fb2bc5f76060b63bcbb1b3e2b94&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1329438683&oauth_token=g3ekXAg9SwoYIge2l1E6JGwIQ02QYiha8uz5TMVA&oauth_verifier=vOrM6QWwGRpTEWgE2Kk2Y87DL1mlx324r4wh2SsUo&oauth_version=1.0
[auth_params] => Array
(
[oauth_consumer_key] => htxmSKEwkd5jPB6z1bQI6Q
[oauth_nonce] => adb19fb2bc5f76060b63bcbb1b3e2b94
[oauth_signature] => E5Vb62A00L8Nj8uyt9MRKdFk6ck%3D
[oauth_signature_method] => HMAC-SHA1
[oauth_timestamp] => 1329438683
[oauth_token] => g3ekXAg9SwoYIge2l1E6JGwIQ02QYiha8uz5TMVA
[oauth_verifier] => vOrM6QWwGRpTEWgE2Kk2Y87DL1mlx324r4wh2SsUo
[oauth_version] => 1.0
)
[request_params] => Array
(
)
[base_string] => POST&https%3A%2F%2Fapi.twitter.com%2Foauth%2Faccess_token&oauth_consumer_key%3DhtxmSKEwkd5jPB6z1bQI6Q%26oauth_nonce%3Dadb19fb2bc5f76060b63bcbb1b3e2b94%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1329438683%26oauth_token%3Dg3ekXAg9SwoYIge2l1E6JGwIQ02QYiha8uz5TMVA%26oauth_verifier%3DvOrM6QWwGRpTEWgE2Kk2Y87DL1mlx324r4wh2SsUo%26oauth_version%3D1.0
[signing_key] => fmNsDdu809uAARz0EslIL5Tj9m3XxLuaTVg6RSVnAQ&4K8chxSWwwQ5nk1HSQrrbNW23FIGWiNLMycoqqxUV0
[auth_header] => OAuth oauth_consumer_key="htxmSKEwkd5jPB6z1bQI6Q", oauth_nonce="adb19fb2bc5f76060b63bcbb1b3e2b94", oauth_signature="E5Vb62A00L8Nj8uyt9MRKdFk6ck%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1329438683", oauth_token="g3ekXAg9SwoYIge2l1E6JGwIQ02QYiha8uz5TMVA", oauth_verifier="vOrM6QWwGRpTEWgE2Kk2Y87DL1mlx324r4wh2SsUo", oauth_version="1.0"
[response] => Array
(
[headers] => Array
(
[date] => Fri, 17 Feb 2012 00:31:23 GMT
[status] => 401 Unauthorized
[x_mid] => 1195d712f355657dc7944ba32517310a873d29e1
[x_revision] => DEV
[x_runtime] => 0.01222
[x_transaction] => c84c1b7c659ad830
[cache_control] => no-cache, no-store, must-revalidate, pre-check=0, post-check=0
[x_frame_options] => SAMEORIGIN
[expires] => Tue, 31 Mar 1981 05:00:00 GMT
[content_type] => text/html; charset=utf-8
[last_modified] => Fri, 17 Feb 2012 00:31:23 GMT
[pragma] => no-cache
[set_cookie] => _twitter_sess=BAh7CDoPY3JlYXRlZF9hdGwrCN1yuIg1ASIKZmxhc2hJQzonQWN0aW9uQ29u%250AdHJvbGxlcjo6Rmxhc2g6OkZsYXNoSGFzaHsABjoKQHVzZWR7ADoHaWQiJWEz%250AMDBiNmY2YmVhODIxZjVlOGMzZjRiODYyMTMzOWRh--d554d0fb6e5d23c9c9a8a10bd72c968c5872ff88; domain=.twitter.com; path=/; HttpOnly
[vary] => Accept-Encoding
[content_encoding] => gzip
[content_length] => 21
[server] => tfe
)
[code] => 401
[response] =>
[info] => Array
(
[url] => https://api.twitter.com/oauth/access_token
[content_type] => text/html; charset=utf-8
[http_code] => 401
[header_size] => 1047
[request_size] => 541
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.52167
[namelookup_time] => 3.3E-5
[connect_time] => 0.119133
[pretransfer_time] => 0.380061
[size_upload] => 0
[size_download] => 21
[speed_download] => 40
[speed_upload] => 0
[download_content_length] => 21
[upload_content_length] => -1
[starttransfer_time] => 0.521456
[redirect_time] => 0
[request_header] => POST /oauth/access_token HTTP/1.1
User-Agent: tmhOAuth 0.61+SSL - //github.com/themattharris/tmhOAuth
Host: api.twitter.com
Accept: */*
Accept-Encoding: deflate, gzip
Authorization: OAuth oauth_consumer_key="htxmSKEwkd5jPB6z1bQI6Q", oauth_nonce="adb19fb2bc5f76060b63bcbb1b3e2b94", oauth_signature="E5Vb62A00L8Nj8uyt9MRKdFk6ck%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1329438683", oauth_token="g3ekXAg9SwoYIge2l1E6JGwIQ02QYiha8uz5TMVA", oauth_verifier="vOrM6QWwGRpTEWgE2Kk2Y87DL1mlx324r4wh2SsUo", oauth_version="1.0"
)
[error] =>
[errno] => 0
)
)
答案 0 :(得分:2)
我遇到了同样的情况 - 我的头靠在墙上 - 终于,终于找到了答案!虽然我使用401代码得到了与tmhOAuth
错误输出相同的错误,但我的错误日志显示为Undefined variable _SESSION
。从这个SO问题中,我发现您需要的只是session_start()
。检查所有包含和所需文件以及实际脚本(即使在if / else条件下),看看你是否没有销毁会话或只是没有启动会话。
我希望这有帮助!
答案 1 :(得分:1)
既然你已经说过代码正在测试服务器而不是生产,那么我认为代码没有任何问题。
希望它有所帮助。
答案 2 :(得分:0)
我不确定,但至少我可以看到你收到错误信息,这是401 Unauthorized。这是你的回应。我也有同样的问题,也使用tmhOAuth
。我建议,为了将来参考,作为一个开始的地方,始终要检查$_SESSION
的内容,因为tmh
存储var
的位置 - 所以,如果你是一个或成功登录的两个步骤,将成为$_SESSION
中的信息。
如果有其他人知道这件事 - 拜托,我仍然被困住了!