Perl 通过刷新令牌的Google oAuth2未经授权的\u客户端

Perl 通过刷新令牌的Google oAuth2未经授权的\u客户端,perl,google-plus,google-oauth,Perl,Google Plus,Google Oauth,我试图在控制台perl脚本中使用oAuth2 web重定向验证中的刷新令牌。客户端id与我在javascript中使用的客户端id相同且正确,我检查了5次,发现它与我在google API控制台中使用的客户端id相同 客户端密码经过两次检查,结果正确 刷新令牌是在approval\u prompt=force&access\u type=offline下创建的 以下是我使用的perl示例代码: # -------------------------------------------------

我试图在控制台perl脚本中使用oAuth2 web重定向验证中的刷新令牌。客户端id与我在javascript中使用的客户端id相同且正确,我检查了5次,发现它与我在google API控制台中使用的客户端id相同

客户端密码经过两次检查,结果正确

刷新令牌是在
approval\u prompt=force&access\u 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;
委员会的答复是:

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"
}
我希望你有个主意能帮上忙


greatings

无效客户端通常意味着客户端ID和客户端机密不匹配,或者其中一个存在键入错误(尽管您提到您已对此进行了双重检查!)。代码中没有任何错误

检索刷新令牌时,是否可以尝试将随附的访问令牌放入Tokenfo端点,并确保其中的客户端ID值与您配置的值匹配:


可能值得转储请求以确保没有错误(例如,内容长度标题太短或类似错误)。

转储请求是关键。为了帮助你,这里有一个我以前烤过的

==POST== 
https://accounts.google.com/o/oauth2/token
refresh_token=1/_PEzU2m71wertwertwerJUtrtrytrytryf3trytryoCo
&client_id=612222222225
&client_secret=Q7334534543534yKLu
&grant_type=refresh_token
您是否使用客户id的缩写形式,即仅使用号码