0

我正在尝试使用本指南的 Google 授权服务。我无法将代码换成来自服务器的令牌。

var token_request='?code='+code+
    '&client_id='+client_id+
    '&client_secret='+client_secret+
    '&redirect_uri='+redirect_uri+
    '&grant_type=authorization_code';

options = {
    host: "accounts.google.com",
    path: '/o/oauth2/token'+token_request,
    method: "POST"
}

var tokenRequest = https.request(options, function(res){
    var resp = "";
    res.on('data', function(data){
        resp+= data;
    })
    res.on('end', function(){
        console.log(resp);
    })
    res.on('error', function(err){
        console.log("\033[;33mIt's an Error.\033[0;39m");
        console.log(err);
    })
}).end();
4

2 回答 2

1

我会从这个网站说你应该使用'method:“GET”'而不是'method:“POST”',因为你的值在查询字符串中。

编辑:

根据评论,我会说您必须重新编写代码才能使其正常工作。

于 2013-03-15T03:31:00.950 回答
0

老实说,我正在努力做同样的事情。尽管如此,还是值得尝试 googleapis。

您需要使用 npm 来安装 google api

npm 安装 googleapis

https://npmjs.org/package/googleapis

对于文档

于 2014-01-13T20:14:33.310 回答