oauth.io subscribe user to youtube channel

纵然是瞬间 提交于 2019-12-13 14:50:42

问题


I'm using oauth.io (https://oauth.io/) to authenticate users via google, facebook, etc. How can I subscribe user to youtube channel after authentication ?

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

  });

回答1:


To subscribe a user to a youtube channel, you need to make sure that you have added the following scopes for Youtube to your OAuth.io app:

  • https://www.googleapis.com/auth/youtube
  • https://www.googleapis.com/auth/youtubepartner

Also make sure that the Youtube API is activated in your Google API console.

Then, you can subscribe the user through OAuth.io like this:

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);
    });

You need to specify the dataType and contentType fields as Google API doesn't accept form encoded data.

You can find more information about this Google API endpoint there:

  • https://developers.google.com/youtube/v3/docs/subscriptions/insert

And if you want to learn more about OAuth.io, you can consult the documentation here:

  • https://oauth.io/docs/overview

You'll also find a tutorial about the JavaScript SDK here:

  • https://oauth.io/getting-started?javascript&None

Hope this helps :)



来源:https://stackoverflow.com/questions/24991626/oauth-io-subscribe-user-to-youtube-channel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!