【问题标题】:Failed to authenticate Service Account credential in Google Cloud Prediction API Library for NodeJS无法在用于 NodeJS 的 Google Cloud Prediction API 库中验证服务帐户凭据
【发布时间】:2016-10-23 03:11:48
【问题描述】:

我正在使用 googleapis 库并使用 JWT 成功验证了我的服务帐户凭据。然后我发现了 google-cloud 库,它具有预测 API 的特定模块,但未能验证相同的服务帐户凭据。

我不使用 Google 计算引擎或 App Engine 并且从事本地开发工作

我遵循文档中的代码:

var key = require('./MY_SERVICE_ACCOUNT_CREDENTIALS.json')
var prediction = require('@google-cloud/prediction')({
  projectId: 'MY_PROJECT_ID',
  credentials: key
})

prediction.getModels((err, models) => {
  if (err) {
    console.log(err)
    return
  }

  console.log('Models:', models)
})

然后它返回:

{ ApiError: Access to project denied: user requires read permissions.                                              
    at [here goes stack trace]                                                                                   
  code: 401,                                                                                                       
  errors:                                                                                                          
   [ { domain: 'global',                                                                                           
       reason: 'authError',                                                                                        
       message: 'Access to project denied: user requires read permissions.',                                       
       locationType: 'header',                                                                                     
       location: 'Authorization' } ],                                                                              
  response: undefined,                                                                                             
  message: 'Access to project denied: user requires read permissions.' } 

我不知道哪里出了问题,我不确定我是否需要使用googleapis 进行身份验证并将其与google-cloud 或等等集成。它也缺乏样本

【问题讨论】:

    标签: node.js authentication google-prediction


    【解决方案1】:

    所以我知道这是几个月前的错误,但错误是不言自明的,但我自己也遇到了这个问题。

    基本上,您的服务密钥没有获得适当的权限,无法从您的项目中读取(或写入)信息。在 Google Cloud Console 的 IAM & Admin 下查找您的服务帐号,然后将 Project → Editor 和/或 Project → Viewer 添加到服务帐号你已经创建了。添加这些权限后,请务必按“保存”,然后等待大约 20 秒以使这些权限生效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-20
      • 2016-12-15
      • 2019-01-10
      • 2019-01-23
      • 1970-01-01
      • 1970-01-01
      • 2013-05-25
      • 2021-10-03
      相关资源
      最近更新 更多