在节点 js 上使用 google api JWT 时出现 CORS 错误
CORS error when using googleapi JWT on nodejs
我正在尝试授权将 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!')
}
})
}
}
}
我正在尝试使用在开发人员控制台中的项目上设置的服务帐户访问数据。
我看不到我错过了什么。
我通过调用我的 server.js 脚本中的脚本修复了它。我的错!
我正在尝试授权将 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!')
}
})
}
}
}
我正在尝试使用在开发人员控制台中的项目上设置的服务帐户访问数据。
我看不到我错过了什么。
我通过调用我的 server.js 脚本中的脚本修复了它。我的错!