Error: “message”: “Login Required” when use Youtube Analytics API

不打扰是莪最后的温柔 提交于 2019-11-29 03:19:48

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.

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
    }
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!