Google Play Android开发人员API 401权限不足

我使用Google Play Android开发人员API服务器来检查用户订阅的订阅状态,但成功授权并询问现有订阅后,我收到401响应,并显示以下消息:“当前用户没有足够的权限执行请求操作“。 访问https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=XXXXXX我可以看到我有请求的范围( https://www.googleapis.com/auth/androidpublisher ),但我仍然得到每次都有同样的反应。 其他人有没有同样的问题?

编辑:我已经看到了什么浏览API应用程序,它添加了请求的查询string中的键,但我没有这个值。 在控制台中,我创build了一个服务帐户客户端ID,它具有一个客户端ID,电子邮件地址和一个私钥,但没有明显的API使用的API密钥。

编辑号码 2:我已经将服务帐户生成的电子邮件添加到Google Play开发者控制台和Google电子钱包控制台,但我仍然没有权限。 我正在使用nodejs和google-oauth-jwt,因为没有为nodejs提供的lib。

这里是我用来提出请求的代码:

var request = require('google-oauth-jwt').requestWithJWT(); function makeReq() { request({ url: 'https://www.googleapis.com/androidpublisher/v1.1/applications/{packageName}/subscriptions/{subscriptionId}/purchases/{purchaseToken}', jwt: { // use the email address of the service account, as seen in the API console email: 'blahblahtrutjtrutj@developer.gserviceaccount.com', // use the PEM file we generated from the downloaded key keyFile: 'purchases-test.pem', // specify the scopes you wish to access scopes: ['https://www.googleapis.com/auth/androidpublisher'] } }, function (err, res, body) { if (err) { console.log(err); } else { console.log("BODY IS ------------------------------------------"); console.log(JSON.parse(body)); } }); } 

有一个电子邮件地址与您的服务帐户相关联。

这需要在开发者控制台和Play商店中具有适当的权限。 确保将服务地址添加到Play商店。

我接触它的方式是使用

 var googleAuth = require('google-oauth-jwt'), authObject = { email: 'blahblahtrutjtrutj@developer.gserviceaccount.com', keyFile: 'purchases-test.pem', scopes: ['https://www.googleapis.com/auth/androidpublisher'] }; googleAuth.authenticate(authObject, function (err, token) { next(err, token); }); 

我将令牌存储在redis中一个小时,然后使用该令牌向商店发出请求:

 var opts = { url : verifyUrl + payload.packageName + '/inapp/' + payload.productId + '/purchases/' + payload.token, headers: { authorization : 'Bearer ' + token } }; request.get(opts, function (error, response, body) { next(error, response, body); }); 
Interesting Posts