Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js (Nodejs)Google oAuth2:缺少必需的参数:grant\u type_Node.js_Oauth 2.0_Request_Google Api - Fatal编程技术网

Node.js (Nodejs)Google oAuth2:缺少必需的参数:grant\u type

Node.js (Nodejs)Google oAuth2:缺少必需的参数:grant\u type,node.js,oauth-2.0,request,google-api,Node.js,Oauth 2.0,Request,Google Api,使用Nodejs和Mikeal的请求拨打此电话。做所有文档要做的事情,包括grant\u type=authorization\u代码,但我仍然不断收到相同的错误。请参阅屏幕截图了解我传递的确切变量和方法 下面是先显式设置grant_类型后的路径 /o/oauth2/token?grant_type=authorization_code&code=4%2F42sz3xxq4wGF9k9joYxRVop9mHi6.UpFaIUqZ_UQaaDn_6y0ZQNh869DgiwI&c

使用Nodejs和Mikeal的请求拨打此电话。做所有文档要做的事情,包括grant\u type=authorization\u代码,但我仍然不断收到相同的错误。请参阅屏幕截图了解我传递的确切变量和方法

下面是先显式设置grant_类型后的路径

/o/oauth2/token?grant_type=authorization_code&code=4%2F42sz3xxq4wGF9k9joYxRVop9mHi6.UpFaIUqZ_UQaaDn_6y0ZQNh869DgiwI&client_id=199079322117.apps.googleusercontent.com&client_secret=...&redirect_uri=...

事实证明,在交换令牌时,需要在初始oauth请求中发送重定向uri,以使其具有可匹配的内容


在这里发布了我的答案,解释了我是如何结束不得不使用弹出窗口构建自己的oauth用户流的(而不是在主应用程序中重定向用户)

你有重定向uri的URL编码吗?我正在使用Nodejs请求库的oauth选项对其进行编码。我最终使用了Nodejs-googleapi的库走了一条不同的路线
Yeah I know its a very old question but I faced the same problem today.
and resolved the  issue as follow. 
if you use form option it will automatically set content type
appticationx-ww-orm-urtencoded



  var request = require('request');
  request.post('https://accounts.google.com/o/oauth2/token',
      {
          form: {
              code: authorization code, // which you get from google 
              client_secret: 'client secret',// its your app secret
              client_id: 'client id', //app client id
              grant_type: 'authorization_code',
              redirect_uri: 'https://developers.google.com/oauthplayground' //this should match the redirect uri which you give while creating the client id
          }
     },function(err,res,body){
         console.log(body);
         if(err) console.log(err);
         //console.log(res);
     });