Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 844
Kishore Avatar asked Jan 20 '16 07:01

Kishore


People also ask

Why is Youtube API not working?

Your API key may not be working because you're using it for the wrong project. Be sure you're using the key for the project that you created it for, especially if you created multiple projects at the same time. If it's still not working, consider creating a new API key entirely.

What are the YouTube reporting and YouTube Analytics APIs?

The YouTube Reporting and YouTube Analytics APIs let you retrieve YouTube Analytics data to automate complex reporting tasks, build custom dashboards, and much more. The Reporting API supports applications that can retrieve and store bulk reports, then provide tools to filter, sort, and mine the data.

Why am I getting a youtubesignuprequired error when logging into YouTube?

This error is commonly seen if you try to use the OAuth 2.0 Service Account flow. YouTube does not support Service Accounts, and if you attempt to authenticate using a Service Account, you will get this error. The YouTube API blog post introducing Google Account support also discusses the youtubeSignupRequired error in more detail.

How to retrieve data from an authorized user's YouTube channel?

For example, to retrieve data about the authorized user's YouTube channel: After your application obtains an access token, you can use the token to make calls to a Google API on behalf of a given user account if the scope (s) of access required by the API have been granted.

How do I call the YouTube Data API from an API?

Build a service object for the API that you want to call. For example, to call version 3 of the YouTube Data API: Make requests to the API service using the interface provided by the service object . For example, to retrieve data about the authorized user's YouTube channel:


Video Answer


2 Answers

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.

like image 187
DaImTo Avatar answered Sep 17 '22 15:09

DaImTo


If someone else using JWT authentication on a Google API stumbles upon this question (eg. when using Service Accounts) then make sure to include auth: <your jwtClient> in your API call, like:

First, get the token:

// Configure JWT auth client
var privatekey = require("./<secret>.json")
var jwtClient = new google.auth.JWT(
  privatekey.client_email,
  null,
  privatekey.private_key,
  ['https://www.googleapis.com/auth/drive']
);

// Authenticate request
jwtClient.authorize(function (err, tokens) {
  if (err) {
    return;
  } else {
    console.log("Google autorization complete");
  }
});

Then, call the API (but don't forget the auth:jwtClient part)

drive.files.create({
    auth: jwtClient,
    resource: {<fileMetadata>},
    fields: 'id'
  }, function (err, file) {
    if (err) {
      // Handle error
    } else {
      // Success is much harder to handle
    }
});
like image 35
David Salamon Avatar answered Sep 21 '22 15:09

David Salamon