0

I'm developing an app with in-app purchases, so I want to know if subscription expired. I've already got my RefreshToken and AccessToken, but when I'm trying to get subscription info according to this, I always get the same error: { "error": { "errors": [
{ "domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization" } ],
"code": 401,
"message": "Invalid Credentials" }}

My code goes here:

 String urlt = " https://www.googleapis.com/androidpublisher/v3/applications/" + PACKAGE_NAME + "/purchases/subscriptions/" + SUBSCR_ID + "/tokens/" + accessToken;
        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet post = new HttpGet(urlt);
        post.setHeader("Scope" , "https://www.googleapis.com/auth/androidpublisher");
        post.setHeader("Authorization" , "Bearer" + accessToken);
        try {
            org.apache.http.HttpResponse response = client.execute(post);
            BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
            StringBuffer buffer = new StringBuffer();
            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                buffer.append(line);
            }

            JSONObject json = new JSONObject(buffer.toString());
           int x = 0;
        }
        catch (Exception e) {
            e.printStackTrace();
        }

Please help ((

  • Referencing [RFC 6750](https://tools.ietf.org/html/rfc6750), there needs to be a space in between "Bearer" and the token. – greeble31 Oct 24 '18 at 22:09
  • Also that "Scope" header doesn't do anything. Google associates your access token with the scope(s) you specified when you were authenticating. – greeble31 Oct 24 '18 at 22:19

1 Answers1

0

Referencing RFC 6750, there needs to be a space in between "Bearer" and the token.

Change your code to this:

post.setHeader("Authorization" , "Bearer " + accessToken);
Community
  • 1
  • 1
greeble31
  • 4,894
  • 2
  • 16
  • 30