Hac*_*ard 9 perl google-plus google-oauth
我正在尝试在我的控制台perl脚本中使用来自oAuth2 web redirect auth的刷新令牌.我的javascript中使用的客户端ID是相同且正确的客户端ID,我检查了5次,它与我在谷歌API控制台中的相同.
客户端密钥被检查两次,这是正确的.
刷新令牌是使用创建的 approval_prompt=force&access_type=offline
这是我使用的perl示例代码:
# -----------------------------------------------------------------------------------
my $CLIENT_ID = 'XXXXX.apps.googleusercontent.com';
my $CLIENT_SECRET = 'YYYYYYYYYYY';
# -----------------------------------------------------------------------------------
# TESTING
my $refresh_token = '1/is_5_minutes_old';
# -----------------------------------------------------------------------------------
my $string = '';
$string .= 'grant_type=refresh_token';
$string .= '&client_id=' . $CLIENT_ID;
$string .= '&client_secret=' . $CLIENT_SECRET;
$string .= '&refresh_token=' . $refresh_token;
$ua = LWP::UserAgent->new;
my $req =
HTTP::Request->new( POST => 'https://accounts.google.com/o/oauth2/token' );
$req->content_type('application/x-www-form-urlencoded');
$req->content($string);
print $string . "\n";
my $res = $ua->request($req);
print $res->as_string;
Run Code Online (Sandbox Code Playgroud)
它的回应:
HTTP/1.1 400 Bad Request
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Connection: close
Date: Mon, 02 Sep 2013 10:50:26 GMT
Pragma: no-cache
Server: GSE
Content-Type: application/json
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Alternate-Protocol: 443:quic
Client-Date: Mon, 02 Sep 2013 10:50:26 GMT
Client-Peer: 74.125.136.84:443
Client-Response-Num: 1
Client-SSL-Cert-Issuer: /C=US/O=Google Inc/CN=Google Internet Authority G2
Client-SSL-Cert-Subject: /C=US/ST=California/L=Mountain View/O=Google Inc/CN=accounts.google.com
Client-SSL-Cipher: RC4-SHA
Client-SSL-Warning: Peer certificate not verified
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
{
"error" : "unauthorized_client"
}
Run Code Online (Sandbox Code Playgroud)
我希望你有一个想法可以提供帮助.
greatings
Ian*_*ber 13
无效的客户端通常意味着客户端ID和客户端密钥不匹配,或者其中一个客户端密码中存在拼写错误(尽管您提到您已经仔细检查过这个!).代码中没有任何内容看起来错误.
当您检索刷新令牌,你可以尝试把自带的访问令牌与它一起进入tokeinfo端点,并确保该值有客户端ID匹配您与配置的那些:https://www.googleapis.com /的oauth2/V1/tokeninfo?=的access_token
可能值得抛弃请求以确保没有错误(例如,内容长度标题太短或类似).