11

I'm using Google client libraries and trying to make a GET request to Google Play API.

        GoogleCredential credential= new GoogleCredential.Builder().setTransport(netHttpTransport)
                .setJsonFactory(jacksonFactory)
                .setServiceAccountId(CLIENT_ID)
                .setServiceAccountScopes(SCOPE)
                .setServiceAccountPrivateKeyFromP12File(file)
                .build();
                credential.refreshToken();     
        HttpRequestFactory requestFactory =netHttpTransport.createRequestFactory(credential);
        GenericUrl url = new GenericUrl(URI);
        HttpRequest request = requestFactory.buildGetRequest(url);
        HttpResponse response = request.execute();

I get

 {
  "code" : 401,
  "errors" : [ {
    "domain" : "androidpublisher",
    "message" : "This developer account does not own the application.",
    "reason" : "developerDoesNotOwnApplication"
  } ],
  "message" : "This developer account does not own the application."
}

My app is unpublished, would that cause the problem?

Andrew Leach
  • 12,945
  • 1
  • 40
  • 47
user1383845
  • 183
  • 1
  • 2
  • 8
  • Similar question: http://stackoverflow.com/questions/11115381/unable-to-get-the-subscription-information-from-google-play-android-developer-ap – Jonathan Naguin Jun 26 '12 at 15:35
  • I finally solved this question, check this out at: http://stackoverflow.com/questions/11115381/unable-to-get-the-subscription-information-from-google-play-android-developer-ap – Jonathan Naguin Oct 03 '12 at 14:48

4 Answers4

6

I've got the same problem. It occurs because you authorize user in Google API who does not own the application and try to get data that belong to your app.

In this topic it is well described. http://support.google.com/googleplay/android-developer/bin/answer.py?hl=en&answer=2528691&topic=16285&ctx=topic

You should authorize by OAuth2 the owner of application, and then use Google API with obtained token.

ikryvorotenko
  • 1,393
  • 2
  • 16
  • 27
  • 1
    To add what ikrovorotenko said pass developer's access token or the user's access token who has been authorized by the developer to access the apps financial data. – Searock Jun 25 '13 at 15:03
4

The problem is you are using the Service accounts OAuth 2.0 flow to authorize to the android-publisher API. I was doing it the same way. However, Google requires to use the Web server applications flow, which is ridiculous, since a human interaction is needed to allow for the API access.

Fortunately there is a way around it. You just have to obtain the refresh_token, store that and keep using it for future API calls. I wrote about it in more detail on my blog.

Milan Cermak
  • 7,476
  • 3
  • 44
  • 59
  • Unfortunately your link is dead, any chance you can republish the information somewhere else or, even better, add it to this answer ? – Jean May 13 '13 at 18:05
  • @Jean I think what Milan is referring to is [under this now](http://milancermak.wordpress.com/2012/08/24/server-side-verification-of-google-play-subsc) – Wojciech Jul 25 '13 at 13:43
  • Thanks Wojciech. I fixed the link now, as I had to migrate away from Posterous. – Milan Cermak Oct 29 '13 at 11:08
  • Saved me so much time and banging of my head in to my desk. Thank you! – Dave Martorana Jul 11 '14 at 20:15
1

We also struggled with this problem as we wanted to validate a purchase on our servers in order to unlock certain features. We tried multiple solutions and frameworks, written by fellow community users and even official implementations but none worked.

Turns out all we had to do was renew our OAuth token (which we just created) and then it all started working.

Johan
  • 176
  • 7
0

I suspect that problem is exactly in publishing. You first need to bind your app to your (developer) account and then you will receive CLIENT_ID and other credentials (such as secret key and so on).

Illia Ratkevych
  • 3,507
  • 4
  • 29
  • 35
  • "Bind your app to your account"? How? Where? In the Google Console API? In the Google Play? – Jonathan Naguin Jun 26 '12 at 14:32
  • If you want to publish Android app on Google Play you should first assign your app to your "publisher account" [here](https://play.google.com/apps/publish/). If you want to use some other API you should to look at appropriate API home site. – Illia Ratkevych Jun 26 '12 at 14:49
  • Consider that registering **new** publishing account costs $25. But adding new app to your existing account is free. – Illia Ratkevych Jun 26 '12 at 14:53
  • I have already a publisher account and it's the same that I used to download the secret key from the Google Play API – Jonathan Naguin Jun 26 '12 at 15:35
  • Did you get client ID? Do you use OAuth? Or something else? – Illia Ratkevych Jun 26 '12 at 16:23
  • I've got the client ID and I'am using OAuth2, see this question with more info: http://stackoverflow.com/questions/11115381/unable-to-get-the-subscription-information-from-google-play-android-developer-ap – Jonathan Naguin Jun 27 '12 at 07:21