Ait*_*tor 5 javascript google-api youtube-api google-authentication oauth-2.0
我有一个应用程序,它使用 Google 登录来获取 YouTube 频道的信息(上传视频、订阅等...)。当用户尝试登录时,他们可以从 Google 帐户列表中进行选择,如果用户拥有多个 YouTube 频道,则可以在之后从 YouTube 频道列表中进行选择。But, when a YouTube channel is selected, the API fails.
var 登录 = 函数(选项){
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);
};
Run Code Online (Sandbox Code Playgroud)
在回调 JavaScript 谷歌 API 中说:
对象 {type: "tokenFailed", idpId: "google", error: "USER_LOGGED_OUT"}
prompt: 'select_account'遇到了类似的问题,经过一段时间的实验后,我让它工作起来,我不完全确定我更改的内容添加到signIn调用选项和fetch_basic_profile: false调用选项中的问题是什么init:
这是一个可能适合您的 jsbin,请确保将您自己的 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);
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
592 次 |
| 最近记录: |