gpt4 book ai didi

javascript - 使用 youtube 帐户的 Google 登录失败

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:42:09 37 4
gpt4 key购买 nike

我有一个应用程序使用 Google 登录来获取 YouTube channel 的信息(上传视频、订阅等)。当用户尝试登录时,他们可以从 Google 帐户列表中进行选择,如果用户有多个帐户,则可以从 Youtube channel 列表中进行选择。 But, when a YouTube channel is selected, the API fails.

var login = function(options) {

if (!gapi.auth2){
// Retrieve the singleton for the GoogleAuth library and set up the client.
gapi.load('auth2', function(){
gapi.auth2.init({
client_id: config.credentials.googleApiClientId,
cookiepolicy: 'single_host_origin',
scope: 'https://www.googleapis.com/auth/youtube.readonly'
});
});
}

var GoogleAuth = gapi.auth2.getAuthInstance();
return GoogleAuth.signIn(options);

};

并且在回调 JavaScript Google API 中说:

Object {type: "tokenFailed", idpId: "google", error: "USER_LOGGED_OUT"}

最佳答案

遇到了类似的问题,经过一段时间的实验后我开始工作了,我不完全确定是什么问题我改变的是添加 prompt: 'select_account'signIn 调用选项和 fetch_basic_profile: falseinit 调用选项:

这是一个 jsbin that might work for you ,确保将您自己的 client_id 添加到 init 调用,并确保将 output.jsbin.com 域列入白名单并从该域预览 jsbin。

var auth2 = gapi.auth2.init({
client_id: '',
scope: 'https://www.googleapis.com/auth/youtube',
fetch_basic_profile: false,
cookie_policy: 'single_host_origin'
});


auth2.signIn({
scope: 'https://www.googleapis.com/auth/youtube',
prompt: 'select_account'
}).then(function(result) {
console.log('Signed in!');
console.log(result);
}, function(error) {
console.log(error);
});

关于javascript - 使用 youtube 帐户的 Google 登录失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34507769/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com