Android publisher api encountered with 403 error

31 Views Asked by At

I'm trying to upload apk using android publisher API but running with issue when hit from python library and postman.

Due to deprecated of python package oauth2client switch to google.oauth2

we are fetching credentials from json file:

credentials = google.oauth2.service_account.Credentials.from_service_account_file('key.json',
                                                                      scopes=['https://www.googleapis.com/auth/androidpublisher'])
        service = build('androidpublisher', 'v3', credentials=credentials) 

After fetching the credentials from json file we are using edits().insert()

edit_request = service.edits().insert(body={}, packageName=self._packagename)
result = edit_request.execute()

Output:

 
INFO:root:<HttpError 403 when requesting https://androidpublisher.googleapis.com/androidpublisher/v3/applications/com.android.sample/edits?alt=json returned "The caller does not have permission". Details: "The caller does not have permission">
 

Generating the token from same json file:

credentials = google.oauth2.service_account.Credentials.from_service_account_file('key.json',
                                                                      scopes=['https://www.googleapis.com/auth/androidpublisher'])
        service = build('androidpublisher', 'v3', credentials=credentials)
request = google.auth.transport.requests.Request()
        credentials.refresh(request)
        logging.info(credentials.token)


copied token authorization with Bearer TO API

API: https://androidpublisher.googleapis.com/androidpublisher/v3/applications/com.android.sample/edits?alt=json

output:

{
    "error": {
        "code": 403,
        "message": "The caller does not have permission",
        "status": "PERMISSION_DENIED"
    }
}

Google Play Android Developer API is already enable in google cloud project. Does any other API need to enabled?

1

There are 1 best solutions below

0
iamwillbin On

There are no additional APIs you typically need to enable for basic functionalities like uploading APKs or managing edits through the Android Publisher API. By just enabling the Google Play Android Developer API in your project is sufficient for using the API with the necessary roles assigned to your service account. If you recently created the service account, it might take up to 24 hours for the role assignment to fully propagate.

You also need to verify if the service account used from Postman has the same roles assigned as the one used in your Python script.

The service account you're using lacks necessary permissions so you might want to try granting "Android Publisher Editor" role for testing purposes.

Here are some resources that might be useful

https://developers.google.com/identity/protocols/oauth2/service-account#python

"403 Forbidden" response from Google Android In App Purchases API with service account