Google Android Developer API 401 Not enough rights

I use the API for developers of Google Play for Android , so that the server controls the subscription status for subscriptions of our users, but after successful authorization and request an existing subscription, I get a 401 response with the following message "The current user does not have enough permissions to perform the second operation." Visit https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=XXXXXX I see that I have the requested area ( https://www.googleapis.com/auth/androidpublisher ), but I still get same answer every time. Has anyone else had the same problem?

Edit: I saw what the Explore API application does, it adds the key to the query string of the request, but I don't have this value. In the console, I created a client identifier for a service account that has a client identifier, email address, and private key, but there is no API key that seems to use the search API.

Change No. 2: I added a message with the service account in both the Google Play Developer Console and the Google Wallet, but I still do not have access. I use nodejs and google-oauth-jwt , because the provided lib is not provided for nodejs.

Here is the code I use to make a request:

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)); } }); } 
+6
source share
1 answer

There is an email address associated with your service account.

For this, appropriate permissions are required both in the dev console and in Play. Remember to add your business address to the Play store.

What I came up with is to use

 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); }); 

I store the token in redis for an hour and use this token to make my request to the repository:

 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); }); 
+1
source

Source: https://habr.com/ru/post/971012/


All Articles