尝试使用新的tmhOAuth并替换旧版本,然后将版本设置为1.1。
之后我在我的php中编辑了代码,并将user_token更改为token,将user_secret更改为secret。
页面进入Twitter登录然后重定向到网站然后使用此代码 $ code = $ tmhOAuth-> user_request(array('url'=> $ tmhOAuth-> url('1.1 / account / verify_credentials')));
错误获取错误在1.0版本之前没有发生错误认证。这是推特回复:
Error: {"errors":[{"message":"Bad Authentication data","code":215}]}
tmhOAuth Object
(
[response] => Array
(
[raw] => HTTP/1.1 400 Bad Request
content-type: application/json; charset=utf-8
date: Mon, 17 Jun 2013 04:18:33 UTC
server: tfe
set-cookie: guest_id=v1%3A137144271317108052; Domain=.twitter.com; Path=/; Expires=Wed, 17-Jun-2015 04:18:33 UTC
strict-transport-security: max-age=631138519
Transfer-Encoding: chunked
Content-Encoding: gzip
{"errors":[{"message":"Bad Authentication data","code":215}]}
[headers] => Array
(
[HTTP/1.1 400 Bad Request] =>
[content-type] => application/json; charset=utf-8
[date] => Mon, 17 Jun 2013 04:18:33 UTC
[server] => tfe
[set-cookie] => guest_id=v1%3A137144271317108052; Domain=.twitter.com; Path=/; Expires=Wed, 17-Jun-2015 04:18:33 UTC
[strict-transport-security] => max-age=631138519
[Transfer-Encoding] => chunked
[Content-Encoding] => gzip
[] =>
)
[code] => 400
[response] => {"errors":[{"message":"Bad Authentication data","code":215}]}
[info] => Array
(
[url] => https://api.twitter.com/1.1/account/verify_credentials.json
[content_type] => application/json; charset=utf-8
[http_code] => 400
[header_size] => 337
[request_size] => 442
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 3.135
[namelookup_time] => 0.093
[connect_time] => 0.53
[pretransfer_time] => 2.621
[size_upload] => 0
[size_download] => 86
[speed_download] => 27
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 3.135
[redirect_time] => 0
[certinfo] => Array
(
)
[primary_ip] => 199.59.150.9
[primary_port] => 443
[local_ip] => 192.168.20.103
[local_port] => 52016
[redirect_url] =>
[request_header] => GET /1.1/account/verify_credentials.json HTTP/1.1
User-Agent: tmhOAuth 0.8.2+SSL - //github.com/themattharris/tmhOAuth
Host: api.twitter.com
Accept: /
Accept-Encoding: deflate, gzip
Authorization: OAuth oauth_consumer_key="whXGehzgX72Jnz6VOwXVBg", oauth_nonce="c3c2f3adde1b18704f267ff8fbffb567", oauth_signature="IeSgCdyRjgJXSvJbfohJxRXGv6Q%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1371442710", oauth_version="1.1"
)
[error] =>
[errno] => 0
)
[buffer] =>
[config] => Array
(
[user_agent] => tmhOAuth 0.8.2+SSL - //github.com/themattharris/tmhOAuth
[host] => api.twitter.com
[consumer_key] => whXGehzgX72Jnz6VOwXVBg
[consumer_secret] => iGXrfjiJ9iyuqMYz1Ild6KHhnpJ9xhqfq7NoiEdtZU
[token] =>
[secret] =>
[bearer] =>
[oauth_version] => 1.1
[oauth_signature_method] => HMAC-SHA1
[curl_connecttimeout] => 30
[curl_timeout] => 10
[curl_ssl_verifyhost] => 2
[curl_ssl_verifypeer] => 1
[use_ssl] => 1
[curl_cainfo] => D:\xampp\htdocs\photolivedesktop\application\libraries\twitter\cacert.pem
[curl_capath] => D:\xampp\htdocs\photolivedesktop\application\libraries\twitter
[curl_followlocation] =>
[curl_proxy] =>
[curl_proxyuserpwd] =>
[curl_encoding] =>
[is_streaming] =>
[streaming_eol] =>
[streaming_metrics_interval] => 10
[as_header] => 1
[force_nonce] =>
[force_timestamp] =>
)
[request_settings] => Array
(
[params] => Array
(
)
[headers] => Array
(
[Authorization] => OAuth oauth_consumer_key="whXGehzgX72Jnz6VOwXVBg", oauth_nonce="c3c2f3adde1b18704f267ff8fbffb567", oauth_signature="IeSgCdyRjgJXSvJbfohJxRXGv6Q%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1371442710", oauth_version="1.1"
)
[with_user] => 1
[multipart] =>
[method] => GET
[without_bearer] =>
[url] => https://api.twitter.com/1.1/account/verify_credentials.json
[oauth1_params] => Array
(
[oauth_consumer_key] => whXGehzgX72Jnz6VOwXVBg
[oauth_nonce] => c3c2f3adde1b18704f267ff8fbffb567
[oauth_signature] => IeSgCdyRjgJXSvJbfohJxRXGv6Q%3D
[oauth_signature_method] => HMAC-SHA1
[oauth_timestamp] => 1371442710
[oauth_version] => 1.1
)
[prepared_params] => Array
(
)
[basestring_params] => oauth_consumer_key=whXGehzgX72Jnz6VOwXVBg&oauth_nonce=c3c2f3adde1b18704f267ff8fbffb567&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1371442710&oauth_version=1.1
[basestring] => GET&https%3A%2F%2Fapi.twitter.com%2F1.1%2Faccount%2Fverify_credentials.json&oauth_consumer_key%3DwhXGehzgX72Jnz6VOwXVBg%26oauth_nonce%3Dc3c2f3adde1b18704f267ff8fbffb567%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1371442710%26oauth_version%3D1.1
[signing_key] => iGXrfjiJ9iyuqMYz1Ild6KHhnpJ9xhqfq7NoiEdtZU&
)
)
有人能告诉我我做错了吗?
由于
答案 0 :(得分:4)
在我遇到以下问题之前没有使用过这个库:
<?php
require 'tmhOAuth.php';
$client= new tmhOAuth( array(
'consumer_key' => '<my app key>',
'consumer_secret' => '<my app secret>',
'token' => '<my access token>',
'secret' => '<my access secret>',
) );
$code = $client->user_request( $client->url('1.1/account/verify_credentials') );
var_dump( $code );
// gives: (int) 200
检查您的credentials,也许您可以完整地发布您正在使用的代码。