Reputation: 989
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
});
Upvotes: 3
Views: 386
Reputation: 513
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:
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:
And if you want to learn more about OAuth.io, you can consult the documentation here:
You'll also find a tutorial about the JavaScript SDK here:
Hope this helps :)
Upvotes: 3