且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Google API OAuth2:使用 Perl 请求服务帐户令牌时出现“invalid_grant"错误

更新时间:2022-12-06 22:46:48

我不知道为什么,但问题出在 curl.

I don't know why, but the problem was with curl.

我将其替换为 WWW::Mechanize:

I replaced it by WWW::Mechanize:

my $mech = WWW::Mechanize->new( autocheck => 1 );
$mech->post('https://accounts.google.com/o/oauth2/token',
    'Content-Type' => 'application/x-www-form-urlencoded',
    'Content' => [
        'grant_type' => 'urn:ietf:params:oauth:grant-type:jwt-bearer',
        'assertion' => $token_request,
    ],
);

它有效.