【问题标题】:Can't access OAuth2 Youtube API V3无法访问 OAuth2 Youtube API V3
【发布时间】:2014-11-19 21:51:06
【问题描述】:

我正在尝试查看我的频道视频列表,但出现此错误invalid_client

未找到 OAuth 客户端。这意味着客户ID是错误的!

var OAUTH2_CLIENT_ID = '############';
var OAUTH2_SCOPES = ['https://www.googleapis.com/auth/youtube'];`

`googleApiClientReady = function () {
    gapi.auth.init(function () {
        window.setTimeout(checkAuth, 1);
    });
}

function checkAuth() {
    gapi.auth.authorize({
        client_id: OAUTH2_CLIENT_ID,
        scope: OAUTH2_SCOPES,
        immediate: true
    }, handleAuthResult);
}

function handleAuthResult(authResult) {
    if (authResult && !authResult.error) {
        $('.pre-auth').hide();
        $('.post-auth').show();
        loadAPIClientInterfaces();
    } else {
        $('#login-link').click(function () {
            gapi.auth.authorize({
                client_id: OAUTH2_CLIENT_ID,
                scope: OAUTH2_SCOPES,
                immediate: false
            }, handleAuthResult);
        });
    }
}

function loadAPIClientInterfaces() {
    gapi.client.load('youtube', 'v3', function () {
        handleAPILoaded();
    });
}

console.google 的截图:

【问题讨论】:

    标签: youtube-api google-oauth youtube-javascript-api


    【解决方案1】:

    您无需连接或使用 Oauth2 即可通过 YouTube API 查看您的视频列表。你只需要一个api key

    一个示例:

    function googleApiClientReady() {
        var apiKey = 'YOUR_API_KEY';
    
        gapi.client.setApiKey(apiKey);
        gapi.client.load('youtube', 'v3', function() {
            isLoad = true;
        }); 
    
        request = gapi.client.youtube.search.list({
            part: id, snippet
            type: 'video',
            order: 'date'
         });
        request.execute(function(response) {
            //list of all your video in the response
    
        });
    }
    

    不要忘记将此文件添加到您的 index.html 并在后面添加以下行:

    <script src="https://apis.google.com/js/client.js?onload=googleApiClientReady"></script>
    

    来自文档YouTube API

    【讨论】:

      猜你喜欢
      • 2013-05-03
      • 2014-08-13
      • 1970-01-01
      • 2015-12-09
      • 2013-10-24
      • 2016-06-22
      • 2019-06-22
      • 1970-01-01
      • 2018-05-26
      相关资源
      最近更新 更多