【问题标题】:Why am i getting an unauthorized message when I use youtube api为什么我在使用 youtube api 时收到未经授权的消息
【发布时间】:2017-11-26 06:17:14
【问题描述】:

我正在尝试获取要显示的播放列表列表并设置我的 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 密钥,确保我的来源被列入白名单,以及我能想到的一切。 但是我一直收到这样的回复:

 "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 调用的窍门,所以如果我忘记添加一些东西,请告诉我。从我从谷歌文档中可以看出,这应该是我所需要的。

【问题讨论】:

标签: javascript ajax youtube


【解决方案1】:

mine

boolean 此参数只能用于properly authorized request。将此参数的值设置为 true 以检索 经过身份验证的用户的活动

正确授权的请求意味着它们实现了 OAuth 2.0 授权 正如上面的链接所示。 要实施 OAuth 2.0 授权,请按照此处的说明进行操作:

https://developers.google.com/youtube/v3/guides/auth/client-side-web-apps

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-03
    • 2014-03-10
    • 2020-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-10
    相关资源
    最近更新 更多