Search code examples
oauthgoogle-apigoogle-oauthyoutube-data-apiyoutube-analytics-api

Error: "message": "Login Required" when use Youtube Analytics API


I am working with youtube api. when I hit this url "https://www.googleapis.com/youtube/analytics/v1/reports?ids=channel%3D%3DMINE&start-date=2015-01-01&end-date=2016-01-31&metrics=likes%2Cdislikes&key={API Key}"

it gives 401

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Login Required",
    "locationType": "header",
    "location": "Authorization"
   }
  ],
  "code": 401,
  "message": "Login Required"
 }
}

but I hited in the explorer "https://developers.google.com/apis-explorer/?" it working fine.
How do I make the first request work?


Solution

  • In your request you are sending key={your key} for an access token you should be sending access_token={your oauth2 access token}

    Note: Key is used for public requests. access token is for authenticated requests.