6

finally I could resolve my recent problems dealing with the OAuth2 authentication for accessing the google API.

But now I'm stuck while querying the android developer API to retrieve status information about subscriptions. I'm using following REST API call:

https://www.googleapis.com/androidpublisher/v1/applications/APP_PACKAGE/subscriptions/SUBSCRIPTION_ID/purchases/PURCHASE_TOKEN?access_token=AUTH_TOKEN

  • APP_PACKAGE The package name of my application which I uploaded to the developer console
  • SUBSCRIPTION_ID The subscription ID specified for the app (developer console)
  • PURCHASE_TOKEN (Yet dummy) purchase token
  • AUTH_TOKEN Auth token retrieved from OAuth2.

The auth token for this request I retrieve as follow:

// Build the HTTP parameter
Map<String,String> params = [:]
params.put("grant_type", "refresh_token")
params.put("refresh_token", googleRefreshToken.encodeAsURL())
params.put("client_id", googleClientId.encodeAsURL())
params.put("client_secret", googleClientSecret.encodeAsURL())

// Send the POST request
// This action might throw an exception in case any parameter were wrong, invalid or not specified.
String result = HttpRequestHandler.sendRequest("https://accounts.google.com/o/oauth2/token", params);
JSONElement jsonResult = JSON.parse(result)

This works pretty fine, but the REST call mentioned above returns a 500 error - without any given message.

{
  "error": {
    "code": 500,
    "message": null
  }
}

I read that some people had almost similar issues, but only when contacting the cancel API.

Some information:

  • The google-user that belongs to the client ID is the owner of the android app as well
  • The app is not yet published
  • The app grants the com.android.vending.BILLING access
  • I also implemented a dummy BillingService and BillingReceiver within the app

Since I do not retrieve any error message I really don't know how to continue right now. Does anyone else know this problem?

EDIT 1

While playing with various test cases I got very weird results. For example: If I use a PURCHASE_TOKEN with <= 7 characters, then I receive following response:

{
  "error": {
    "errors": [
     {
      "domain": "global",
      "reason": "notFound",
      "message": "The subscription purchase token was not found.",
      "locationType": "parameter",
      "location": "token"
     }
    ],
   "code": 404,
   "message": "The subscription purchase token was not found."
  }
}

Whereas I still get the 500 error when I use a PURCHASE_TOKEN > 7 characters. Like an example token copied from here: rojeslcdyyiapnqcynkjyyjh

EDIT 2

Every here and then the server does even response a 503 Backend Error, randomly.

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "Backend Error"
   }
  ],
  "code": 503,
  "message": "Backend Error"
 }
}

EDIT 3

If I use the Java API (instead of the direct URL call) I get the same errors.

// Build token for the response
TokenResponse tokenResponse = new TokenResponse();
tokenResponse.setAccessToken(googleAccessToken);
tokenResponse.setRefreshToken(googleRefreshToken);
tokenResponse.setExpiresInSeconds(3600L);
tokenResponse.setScope(OAuth2Handler.SCOPE_ANDROID_PUBLISHER);
tokenResponse.setTokenType("Bearer");

// Init credential container
HttpRequestInitializer credential =  new GoogleCredential.Builder()
.setTransport(HTTP_TRANSPORT)
.setJsonFactory(JSON_FACTORY)
.setClientSecrets(googleClientId, googleClientSecret)
.build()
.setFromTokenResponse(tokenResponse);

// Connect to the android publisher API
Androidpublisher publisher = new Androidpublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
    .setApplicationName("NameOfMyApplicationInGooglePlayStore")
    .build();

// Retrieve subscription purchase information
Androidpublisher.Purchases purchases = publisher.purchases();
Androidpublisher.Purchases.Get get = purchases.get(
    packageName,
    subscriptionId,
    purchaseToken
);

// Analyse result
SubscriptionPurchase subscription = get.execute();        

Kind regards, Christopher

Community
  • 1
  • 1
Christopher Will
  • 2,991
  • 3
  • 29
  • 46
  • not sure whats your exact problem. I have it working in my code base. Is the auth API the problem or the actually subscription API where you use the auth token? Use the Chrome Plugin "Postman" for easier API debugging then your code. – philipp Mar 20 '13 at 22:19
  • Same here, using Androidpublisher.Purchases.Get every now and then I get the 503 (backend error). Can't figure out what the problem is!? – Stefan Jul 10 '13 at 08:48
  • Anyone ever figure this out? I am having a similar error described [here](http://stackoverflow.com/questions/28441359/500-httperror-when-trying-to-extend-googlesamples-android-play-publisher-api-to). Thanks. – weemattisnot Feb 12 '15 at 20:31

0 Answers0