YouTube channel subscribe for Android

2019-06-23 19:57发布

问题:

I am using the YouTube API within my app. Users can log in with their Google+ account. I would like the user to be able to subscribe to certain YouTube channels.

There seems to be something for web here: https://developers.google.com/youtube/subscribe/

But I can't find something suited to Android. Am I missing something from the documentation or is there a workaround?

回答1:

You don't need a specific Android library to subscribe an authenticated user to a specific channel. Just send an authenticated POST request to the subscriptions/insert endpoint with the channelId of the channel you want to subscribe to with the Part param snippet:

HTTP POST https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&key={YOUR_API_KEY}

Request body:

{
    "snippet": {
        "resourceId": {
            "channelId": "XXXXX" // channel ID you want to subscribe to
        }
    }
}


回答2:

I found we can subcription with request body as:

{
  "snippet": {
    "resourceId": {
      "channelId": "your channel Id",
        "kind": "youtube#channel"
    }
  }
}

source: https://mshibanami.github.io/en/blog/subscriptions-insert-error/