【发布时间】:2020-09-21 05:52:41
【问题描述】:
我正在研究如何使用 YT API v3 进行简单搜索,我查看了 https://github.com/youtube/api-samples/tree/master/javascript 然后我使用 ExpressJS(在 GCP 中正确授权 localhost:5000)并创建 API 密钥和 OAuth 进行了尝试GCP 上的凭据,但是当我运行测试时,它在执行以下函数时给出了一个奇怪的错误:
// Handle the result of a gapi.auth.authorize() call.
function handleAuthResult(authResult) {
//Here I printed the authResult to see what was going on
console.log(authResult)
if (authResult && !authResult.error) {
// Authorization was successful. Hide authorization prompts and show
// content that should be visible after authorization succeeds.
$('.pre-auth').hide();
$('.post-auth').show();
loadAPIClientInterfaces();
} else {
// Make the #login-link clickable. Attempt a non-immediate OAuth 2.0
// client flow. The current function is called when that flow completes.
$('#login-link').click(function() {
gapi.auth.authorize({
client_id: OAUTH2_CLIENT_ID,
scope: OAUTH2_SCOPES,
immediate: false
}, handleAuthResult);
});
}
}
当我打印变量 authResult 时,它给了我以下对象:
>{
"error": "immediate_failed",
"error_subtype": "no_user_bound",
{
"error": "immediate_failed",
"error_subtype": "no_user_bound",
"status": {
"signed_in": false,
"method": null,
"google_logged_in": false
},
"client_id": "MY_CLIENT_ID",
"cookie_policy": "single_host_origin"
}
我在“MY_CLIENT_ID”中的哪个位置放置了我的 OAuth 客户端 ID。我真的不知道如何解决这个问题,我搜索了整个 stackoverflow,发现最接近的是gapi.client.youtube is undefined?。
【问题讨论】:
标签: javascript api oauth youtube