я пытаюсь получить авторизацию для получения токена и затем использовать API Proximity Beacon, я использую этот код:
const defaultScope = [
'https://www.googleapis.com/auth/userlocation.beacon.registry',
];
const {JWT} = require('google-auth-library');
const keys = require('./Streamy-70cb53004c67.json');
async function main() {
const client = new JWT(
keys.client_email,
null,
keys.private_key,
defaultScope,
);
const url = `https://www.googleapis.com/dns/v1/projects/${keys.project_id}`;
const res = await client.request({url});
console.log(res.data);
}
main().catch(console.error);
Это вывод:
{ Error: Request had insufficient authentication scopes.
at Gaxios.<anonymous> (/home/mariano/Documents/MarketPlace/apiBeacon/node_modules/gaxios/build/src/gaxios.js:72:27)
at Generator.next (<anonymous>)
at fulfilled (/home/mariano/Documents/MarketPlace/apiBeacon/node_modules/gaxios/build/src/gaxios.js:16:58)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
response:
{ config:
{ url: 'https://www.googleapis.com/dns/v1/projects/streamy-225917',
headers: [Object],
validateStatus: [Function: validateStatus],
paramsSerializer: [Function: paramsSerializer],
responseType: 'json',
method: 'GET' },
data: { error: [Object] },
headers:
{ 'alt-svc': 'quic=":443"; ma=2592000; v="44,43,39"',
'cache-control': 'private',
connection: 'close',
'content-encoding': 'gzip',
'content-type': 'application/json; charset=UTF-8',
date: 'Thu, 21 Feb 2019 17:11:00 GMT',
server: 'ESF',
'transfer-encoding': 'chunked',
vary: 'Origin, X-Origin, Referer',
'www-authenticate': 'Bearer realm="https://accounts.google.com/", error="insufficient_scope", scope="https://www.googleapis.com/auth/cloud-platform https://www.googleapis.com/auth/cloud-platform.read-only https://www.googleapis.com/auth/ndev.clouddns.readonly https://www.googleapis.com/auth/ndev.clouddns.readwrite"',
'x-content-type-options': 'nosniff',
'x-frame-options': 'SAMEORIGIN',
'x-xss-protection': '1; mode=block' },
status: 403,
statusText: 'Forbidden' },
config:
{ url: 'https://www.googleapis.com/dns/v1/projects/streamy-225917',
headers:
{ Authorization: 'Bearer ya29.c.Ely3BopPHoY6oEdc9BMYloyWpP70-KNj5dyEtotqkiX8LmDYkI4SHtdimmZuF6mdnm6jO0wj4A0s2iduscF--x0z36-4Yze7y4liRCbTrTf9ZxVIbXlV4k5b9ze4Xw',
'User-Agent': 'google-api-nodejs-client/3.1.0',
Accept: 'application/json' },
validateStatus: [Function: validateStatus],
paramsSerializer: [Function: paramsSerializer],
responseType: 'json',
method: 'GET' },
code: 403,
errors:
[ { message: 'Request had insufficient authentication scopes.',
domain: 'global',
reason: 'forbidden' } ] }
Я думаю, что-то со сферой, но не знаю.В любом случае, в этом посте они использовали одно и то же: https://www.protechtraining.com/blog/post/887