【问题标题】:oauth.io subscribe user to youtube channeloauth.io 订阅用户到 youtube 频道
【发布时间】:2014-09-19 10:15:00
【问题描述】:

我正在使用 oauth.io (https://oauth.io/) 通过 google、facebook 等对用户进行身份验证。如何在身份验证后为用户订阅 youtube 频道?

  OAuth.popup(provider, function(error, result) {
    // some code to subscribe user to youtube channel

  });

【问题讨论】:

    标签: oauth oauth-2.0 youtube-api google-api-client


    【解决方案1】:

    要为用户订阅 youtube 频道,您需要确保已将以下 Youtube 范围添加到您的 OAuth.io 应用:

    还要确保在您的 Google API 控制台中激活了 Youtube API。

    然后,您可以像这样通过 OAuth.io 订阅用户:

    OAuth.popup('youtube')
        .done(function (requestObject) {
             requestObject.post('/youtube/v3/subscriptions?part=snippet', { 
                 data: JSON.stringify({ 
                     snippet: { 
                         resourceId: { 
                             channelId: 'id_of_the_channel' 
                         }
                     } 
                 }), 
                 dataType: 'json', 
                 contentType: 'application/json; charset=utf8' 
             })
             .done(function (r) {
                   // Success: the subscription was successful
                   console.log(r);
             })
             .fail(function (e) {
                   // Failure: the id was wrong, or the subscription is a duplicate
                   console.log(e);
             });
        })
        .fail(function (e) {
             // Handle errors here
             console.log(e);
        });
    

    您需要指定 dataType 和 contentType 字段,因为 Google API 不接受表单编码数据。

    您可以在此处找到有关此 Google API 端点的更多信息:

    如果您想了解有关 OAuth.io 的更多信息,可以在此处查阅文档:

    您还可以在此处找到有关 JavaScript SDK 的教程:

    希望这会有所帮助:)

    【讨论】:

    猜你喜欢
    • 2013-03-16
    • 2015-10-14
    • 1970-01-01
    • 2012-12-02
    • 1970-01-01
    • 1970-01-01
    • 2013-06-15
    • 2013-09-29
    相关资源
    最近更新 更多