错误:invalid_request getToken [英] Error: invalid_request getToken

查看:248
本文介绍了错误:invalid_request getToken的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google的开发者控制台:

  1. 我已经创建了一个项目,并为该项目创建了一个客户端.
  2. 我已经激活了Youtube API数据
  3. 我将回调设置为 http://localhost:3000/callback
  4. 我已经下载了"client_secrets".
  1. I have created a project and created a client for that project.
  2. I have activated Youtube API Data
  3. I set a the callback to http://localhost:3000/callback
  4. I have downloaded the "client_secrets".

节点服务器的初始步骤:

  1. 使用"client_secrets"创建了一个名为oauth2Client的新OAuth2Client实例
  2. 我使用oauth2Client变量生成了URL,并指定了以下内容:


var url = oauth2Client.generateAuthUrl({
            access_type: 'offline', //returns fresh token,
            scope: 'https://www.googleapis.com/auth/youtube https://www.googleapis.com/auth/youtube.upload https://www.googleapis.com/auth/youtube.force-ssl https://www.googleapis.com/auth/youtubepartner'
        });


Google授权页面:

  1. 我转到生成的URL,然后单击授权并重定向到 http://localhost:3000/callback

节点服务器的最终步骤:

  1. 我在URL中获得了代码"(看起来像这样: 4/gZpLEwZWD6OVEE7F5uXXXXXXXXXXXXXXXXX )
  2. 使用相同的oauth2Client变量,我试图像这样获取令牌:


oauth2Client.getToken(code, function (err, tokens) {
    // set tokens to the client
    console.log('errors ' + err);
    console.log('tokens ' + tokens);
    oauth2Client.setCredentials(tokens);
})


console.log的结果是:


The result from the console.log's are:

 errors Error: invalid_request
 tokens null

问题

是什么原因导致invalid_request?我错过了哪一部分?

Question

What is causing the invalid_request? What part did I miss?

其他一些类似的问题提出了不同的解决方案

Some other similar questions propose different solutions

关于这个主题,似乎有很多问题,但是大多数都是特定的问题,答案往往含糊不清. 我在问一个通用的问题,并寻找一个具体的答案.

There seem to be quite a few questions on this subject, but most are specific questions with too often very vague answers. I'm asking a generic question and looking for a specific answer.

推荐答案

您没有提到oauth2Client实例的构造,因此在GutHub

You didn't mention constructing of oauth2Client instance, so it can be a problem from lib issue on GutHub google-api-nodejs-client/issues/231

即,构造函数OAuth2中的第三个参数将是字符串

Namely, the third argument in constructor OAuth2 is going be a string

client_secrets.web.redirect_uris[0]


var oauth2Client = new OAuth2Client(
 client_secrets.web.client_id, 
 client_secrets.web.client_secret, 
 client_secrets.web.redirect_uris[0] //<-- take first uri
);

这篇关于错误:invalid_request getToken的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆