【问题标题】:CORS error when using googleapi JWT on nodejs在nodejs上使用googleapi JWT时出现CORS错误
【发布时间】: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


    【解决方案1】:

    我通过调用我的 server.js 脚本中的脚本来修复它。我的错!

    【讨论】:

      猜你喜欢
      • 2019-11-09
      • 2021-03-02
      • 2020-08-28
      • 1970-01-01
      • 2023-01-12
      • 2021-09-13
      • 1970-01-01
      • 2020-07-02
      • 2020-08-07
      相关资源
      最近更新 更多