我使用Google Play Android Developer API到服务器到服务器检查我们用户订阅的订阅状态,但在成功授权并请求现有订阅后,我得到了带有以下消息的401响应:“当前用户没有足够的权限执行请求的操作”。访问https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=XXXXXX时,我可以看到我确实有请求的作用域(https://www.googleapis.com/auth/androidpublisher),但每次我仍然得到相同的响应。其他人也有同样的问题吗?
编辑:我已经看到Explore API应用程序做了什么,它将键添加到请求的查询字符串中,但我没有这个值。在控制台中,我创建了一个服务帐户客户端id,它有一个客户端Id、电子邮件地址和一个私钥,但没有明显的Explore 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));
}
});
}发布于 2019-11-02 03:05:59
如果你的应用只在封闭的alpha轨道中发布,你还必须将你的服务帐户的电子邮件地址(client_email)添加到Play控制台中设置-> Account detail的许可证测试人员中。
发布于 2014-07-03 06:45:05
有一个与您的服务帐户关联的电子邮件地址。
这需要在开发控制台和Play store中都具有适当的权限。确保将服务地址添加到Play store。
我处理它的方法是使用
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);
});https://stackoverflow.com/questions/24287429
复制相似问题