title: 500 Internal Server Error for GET on www.googleapis.com/androidpublisher/v1/
body: <p>finally I could resolve my <a href="https://stackoverflow.com/questions/12605182/checking-google-android-subscriptions-from-server-side">recent problems</a> dealing with the OAuth2 authentication for accessing the google API.</p>
  
  <p>But now I'm stuck while querying the android developer API to retrieve status information about subscriptions.
  I'm using following REST API call:</p>
  
  <p><a href="https://www.googleapis.com/androidpublisher/v1/applications/" rel="nofollow noreferrer">https://www.googleapis.com/androidpublisher/v1/applications/</a><strong>APP_PACKAGE</strong>/subscriptions/<strong>SUBSCRIPTION_ID</strong>/purchases/<strong>PURCHASE_TOKEN</strong>?access_token=<strong>AUTH_TOKEN</strong></p>
  
  <ul>
  <li><strong>APP_PACKAGE</strong>     The package name of my application which I uploaded to the <a href="https://play.google.com/apps/publish/Home" rel="nofollow noreferrer">developer console</a></li>
  <li><strong>SUBSCRIPTION_ID</strong> The subscription ID specified for the app (developer console)</li>
  <li><strong>PURCHASE_TOKEN</strong>  (Yet dummy) purchase token</li>
  <li><strong>AUTH_TOKEN</strong>      Auth token retrieved from OAuth2.</li>
  </ul>
  
  <p>The auth token for this request I retrieve as follow:</p>
  
  <pre><code>// Build the HTTP parameter
  Map&lt;String,String&gt; 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)
  </code></pre>
  
  <p>This works pretty fine, but the REST call mentioned above returns a 500 error - without any given message.</p>
  
  <pre><code>{
    "error": {
      "code": 500,
      "message": null
    }
  }
  </code></pre>
  
  <p>I read that some people had almost similar issues, but only when contacting the <a href="https://developers.google.com/android-publisher/v1/purchases/cancel" rel="nofollow noreferrer">cancel API</a>.</p>
  
  <p>Some information:</p>
  
  <ul>
  <li>The google-user that belongs to the client ID is the owner of the android app as well</li>
  <li>The app is not yet published</li>
  <li>The app grants the com.android.vending.BILLING access</li>
  <li>I also implemented a dummy BillingService and BillingReceiver within the app</li>
  </ul>
  
  <p>Since I do not retrieve any error message I really don't know how to continue right now.
  Does anyone else know this problem?</p>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>While playing with various test cases I got very weird results.
  For example:
  If I use a PURCHASE_TOKEN with &lt;= 7 characters, then I receive following response:</p>
  
  <pre><code>{
    "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."
    }
  }
  </code></pre>
  
  <p>Whereas I still get the 500 error when I use a PURCHASE_TOKEN > 7 characters.
  Like an example token copied from <a href="http://developer.android.com/guide/google/play/billing/billing_subscriptions.html" rel="nofollow noreferrer">here</a>:
  rojeslcdyyiapnqcynkjyyjh</p>
  
  <p><strong>EDIT 2</strong></p>
  
  <p>Every here and then the server does even response a 503 Backend Error, randomly.</p>
  
  <pre><code>{
   "error": {
    "errors": [
     {
      "domain": "global",
      "reason": "backendError",
      "message": "Backend Error"
     }
    ],
    "code": 503,
    "message": "Backend Error"
   }
  }
  </code></pre>
  
  <p><strong>EDIT 3</strong></p>
  
  <p>If I use the Java API (instead of the direct URL call) I get the same errors.</p>
  
  <pre><code>// 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();        
  </code></pre>
  
  <p>Kind regards,
   Christopher</p>