Search code examples
google-apiyoutube-apigoogle-oauthyoutube-data-api

Get the full list of my own YouTube channel's subscriber


I am trying to get the full list of my own channel's subscribers, but this does not work.

https://www.googleapis.com/youtube/v3/subscriptions?part=snippet&mine=true&key=[API_KEY]

I am following the official documentation https://developers.google.com/youtube/v3/docs/subscriptions/list

But get this error

{
  "error": {
    "code": 401,
    "message": "The request uses the \u003ccode\u003emine\u003c/code\u003e parameter but is not properly authorized.",
    "errors": [
      {
        "message": "The request uses the \u003ccode\u003emine\u003c/code\u003e parameter but is not properly authorized.",
        "domain": "youtube.parameter",
        "reason": "authorizationRequired",
        "location": "mine",
        "locationType": "parameter"
      }
    ]
  }
}

Solution

  • Currently you are only using an api key which will only give you access to public data, using mine is private user data and will require authorization.

    This can be seen in the documentation page for Subscriptions: list States

    enter image description here

    This means that you must be authorized using Oauth2 to access the subscriptions for this channel. You will then have an access token that you can send as an authorization header bearer token.

    GET https://youtube.googleapis.com/youtube/v3/subscriptions?part=snippet&mine=true&key=[YOUR_API_KEY] HTTP/1.1
    
    Authorization: Bearer [YOUR_ACCESS_TOKEN]
    Accept: application/json