我的项目正在使用带有 gmail oauth 的 php 并面临此错误为 401 Target Invalid ,其中另一个项目使用相同的方式(不同的 ID 和 Secret 但相同的域)工作正常。例如:-
xxx.com/abc xxx.com/def
HTTP/1.1 401 Token invalid - Target is invalid.
Content-Type: text/html; charset=utf-8
Date: Mon, 19 May 2014 02:03:50 GMT
Expires: Mon, 19 May 2014 02:03:50 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alternate-Protocol: 443:quic
Transfer-Encoding: chunked
我该如何解决这个问题?感谢任何评论和帮助。
GmailOath 代码
$url = 'https://www.google.com/accounts/OAuthGetRequestToken';
$params['oauth_version'] = '1.0';
$params['oauth_nonce'] = mt_rand();
$params['oauth_timestamp'] = time();
$params['oauth_consumer_key'] = $oauth->oauth_consumer_key;
$params['oauth_callback'] = $oauth->callback;
$params['scope'] = 'https://www.google.com/m8/feeds';
更新: 我猜这可能是问题所在。下面不同的是内容类型,它应该是“应用程序/json”。但是不知道在哪里更改它们...
更新:经过进一步调查,它只有在我在https://console.developers.google.com/ 替换旧应用程序的客户端 ID 和 Secret 后才能工作。无论我尝试生成多少个新应用程序的密钥,它只是不工作。发生了什么?
工作电话:-
[url] => https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000&oauth_consumer_key=59093836836-0c8mb4u395gklok3k52cr2b0oml3gmcg.apps.googleusercontent.com&oauth_nonce=1103659829&oauth_signature=ORgJZEli8Y0b1Bv1xUwFWysdJgA%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1400465100&oauth_token=1%2FL0o-ttvJP0haJ2RF9I-jd6hOIW2-kFYiQmlNx7UWVkw&oauth_version=1.0
[content_type] => application/json; charset=UTF-8
[http_code] => 200
[header_size] => 525
[request_size] => 743
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 2.250314
[namelookup_time] => 4.7E-5
[connect_time] => 0.012625
[pretransfer_time] => 0.040877
[size_upload] => 0
[size_download] => 997382
[speed_download] => 443219
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0.423671
[redirect_time] => 0
不工作的电话: -
[url] => https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=1000&oauth_consumer_key=59093836836-57psirebb7ntghd1259g4iiml5eq0l70.apps.googleusercontent.com&oauth_nonce=995553446&oauth_signature=8yPK5su1np6sC0z8vmZ%2BHOW7CuE%3D&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1400465030&oauth_token=1%2FrDfOd04W2oUs2MHfLoFIJoVngnM0n3MWZwWMRoeFDOg&oauth_version=1.0
[content_type] => text/html; charset=utf-8
[http_code] => 401
[header_size] => 369
[request_size] => 745
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.337964
[namelookup_time] => 4.7E-5
[connect_time] => 0.017053
[pretransfer_time] => 0.054309
[size_upload] => 0
[size_download] => 11875
[speed_download] => 35136
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0.337551
[redirect_time] => 0
如果上述问题不完整,请询问更多信息。谢谢。