问题
I'm using node.js google api (npm gcloud package) to create a new project. this is a beta API. I'm getting an error: "The caller does not have permission" stack:
ApiError: The caller does not have permission at new util.ApiError (C:\app\bundle\a2\node_modules\gcloud\lib\common\util.js:92:10) at Object.parseHttpRespBody (C:\app\bundle\a2\node_modules\gcloud\lib\common\util.js:170:30) at Object.handleResp (C:\app\bundle\a2\node_modules\gcloud\lib\common\util.js:110:18) at C:\app\bundle\a2\node_modules\gcloud\lib\common\util.js:422:12 at Request.onResponse [as _callback] (C:\app\bundle\a2\node_modules\gcloud\node_modules\retry-request\index.js:117:7) at Request.init.self.callback (C:\app\bundle\a2\node_modules\gcloud\node_modules\request\request.js:199:22) at Request.emit (events.js:110:17) at Request. (C:\app\bundle\a2\node_modules\gcloud\node_modules\request\request.js:1036:10) at Request.emit (events.js:129:20) at IncomingMessage. (C:\app\bundle\a2\node_modules\gcloud\node_modules\request\request.js:963:12)
I already enabled "Google Cloud Resource Manager API". Other calls works OK. What may be the problem?
回答1:
The Cloud Resource Manager's projects.create
method is invite only per their documentation:
The projects.create() method is in the Alpha stage. It might be changed in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy. Access to this feature is currently invite-only. For an invitation, contact our sales team.
回答2:
For that method, you must be authenticated as yourself, i.e. a service account JSON file won't work here. The only way to do that that I know of is by installing the gcloud SDK (https://cloud.google.com/sdk) and running gcloud auth login
. When you instantiate gcloud, don't provide any credentials, only your project ID:
var gcloud = require('gcloud');
var resource = gcloud.resource({ projectId: 'grape-spaceship-123' });
// Now this should work:
resource.createProject('grape-spaceship-124', function(err, project) {});
Related material:
- gcloud SDK installation guide: https://cloud.google.com/sdk
- gcloud-node createProject API docs: https://googlecloudplatform.github.io/gcloud-node/#/docs/v0.27.0/resource?method=createProject
来源:https://stackoverflow.com/questions/35293010/the-caller-does-not-have-permission-error-when-creating-new-project-using-node