【发布时间】:2018-02-15 16:51:25
【问题描述】:
我正在尝试授权将 JWT 与 googleapis 一起使用,以便能够访问分析数据,但我正在尝试
POST https://accounts.google.com/o/oauth2/token 400 ()
Failed to load https://accounts.google.com/o/oauth2/token: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 400. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
TypeError: Failed to fetch
当我运行这段代码时。
import google from 'googleapis'
const key = require('../../../static/key.json')
export const GA = {
methods: {
getVisits () {
var jwtClient = new google.auth.JWT(
key.client_email,
null,
key.private_key,
['https://www.googleapis.com/auth/analytics.readonly'] // an array of auth scopes
)
jwtClient.authorize(function (err, tokens) {
if (err) {
console.log(err)
// return
} else {
console.log('Successfully connected!')
}
})
}
}
}
我正在尝试使用在开发者控制台中的项目上设置的服务帐户访问数据。
我看不到我错过了什么。
【问题讨论】:
标签: javascript node.js jwt google-analytics-api