我正在尝试获取要显示的播放列表列表,并将我的 ajax 调用设置为:
function loadData(){
if(GoogleAuth.currentUser.get().hasGrantedScopes(SCOPE)){
$.ajax({
url:'https://www.googleapis.com/youtube/v3/playlists',
data:{
'key':'AIzaSyD0OY6xhl9gP9CmPXvU-rN-purRDaTrip8',
'mine':'true',
'maxResults':'5',
'part':'snippet,contentDetails'
},
sucess:function(data){
console.log(data);
},
error:function(data){
console.log(data.responseText);
}
});
}
}
此代码仅在页面完全加载并且用户可以选择登录后运行。如果他们登录,则应构建播放列表列表。我已启用我的 api key ,确保我的来源已列入白名单,以及我能想到的所有其他内容。 但是我不断收到这样的回复:
"error": {
"errors": [
{
"domain": "youtube.parameter",
"reason": "authorizationRequired",
"message": "The request uses the \u003ccode\u003emine\u003c/code\u003e parameter but is not properly authorized.",
"locationType": "parameter",
"location": "mine"
}
],
"code": 401,
"message": "The request uses the \u003ccode\u003emine\u003c/code\u003e parameter but is not properly authorized."
}
我已确保包装 ajax 调用以确保用户已登录。所以我不确定为什么会收到此错误消息。我仍在掌握 api 调用的窍门,所以如果我忘记添加一些内容,请告诉我。从我从谷歌文档中可以看出,这应该是我所需要的。
最佳答案
boolean This parameter can only be used in a properly authorized request. Set this parameter's value to true to retrieve a feed of the authenticated user's activities
正确授权的请求意味着它们实现了 OAuth 2.0 授权 正如上面的链接所示。 要实现 OAuth 2.0 授权,请按照此处的说明进行操作:
https://developers.google.com/youtube/v3/guides/auth/client-side-web-apps
关于javascript - 为什么我在使用 youtube api 时收到未经授权的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44708358/