Proble to get Google Play subscription info using Google Developers API

190 views
Skip to first unread message

Michael Ginzburg

unread,
Jul 3, 2017, 4:35:43 AM7/3/17
to Google App Engine


Hi, we are trying to get Google Play subscription information connected to one of our Android applications.

The first step is authorizes and gets subscriptions json.


Has anyone succeed to work with Google Play Developer API? Autorization? Subscriptions list?

Our main problem is “How to get token?”

Because we are keep getting error never mind which method we use

We tried all from here for example (not only)

https://stackoverflow.com/questions/11115381/unable-to-get-the-subscription-information-from-google-play-android-developer-ap


=========================================================================

When we use “Oath 2.0 Playground", we are getting

{

  "access_token": "ya29.Glt6BA……..E2m82",

  "token_type": "Bearer",

  "expires_in": 3600,

  "refresh_token": "1/3X3bEzKbU,,,,,,,,,,,ZkQGEbewn"

}

 

But, when we run step 1 on the web


https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=urn:ietf:wg:oauth:2.0:oob&client_id=298357274244-9sp4bkpjet9peg6hp9erpuq52j1a1o3p.apps.googleusercontent.com


we are getting


4/K49JHYkYGaLbmRRU5CvAgPzfgo-DpSYQnkl06J-Sfx8


Then we paste it in our code and run post from our Android app we are getting error


java.io.FileNotFoundException: https://accounts.google.com/o/oauth2/token


we use


URL url = new URL("https://accounts.google.com/o/oauth2/token");

 

"Oath 2.0 Playground use


https://accounts.google.com//oauth2/v4/token


We try both but getting the same error

Here is the app code


Map<String,Object> params = new LinkedHashMap<>();

params.put("grant_type","authorization_code");

params.put("client_id","298357274244-9sp4bkpjet9peg6hp9erpuq52j1a1o3p.apps.googleusercontent.com");

params.put("client_secret","client_secret_298357274244-9sp4bkpjet9peg6hp9erpuq52j1a1o3p.apps.googleusercontent.com");

params.put("code",4/K49JHYkYGaLbmRRU5CvAgPzfgo-DpSYQnkl06J-Sfx8);

params.put("scope",AndroidPublisherScopes.ANDROIDPUBLISHER);

params.put("redirect_uri","urn:ietf:wg:oauth:2.0:oob");

 

StringBuilder postData = new StringBuilder();

for(Map.Entry<String,Object> param : params.entrySet())

{

    if(postData.length() != 0)

    {

        postData.append('&');

    }

    postData.append(URLEncoder.encode(param.getKey(),"UTF-8"));

    postData.append('=');

    postData.append(URLEncoder.encode(String.valueOf(param.getValue()),"UTF-8"));

}

byte[] postDataBytes = postData.toString().getBytes("UTF-8");

 

URL url = new URL("https://accounts.google.com/o/oauth2/token");

HttpURLConnection conn = (HttpURLConnection)url.openConnection();

conn.setDoOutput(true);

conn.setUseCaches(false);

conn.setRequestMethod("POST");

conn.getOutputStream().write(postDataBytes);

 

BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));

 

 

George (Cloud Platform Support)

unread,
Jul 4, 2017, 11:49:48 AM7/4/17
to Google App Engine
Hello Michael, 

The information you need is presented in a step-by-step format on the "Authorization" documentation page. You'll get the desired token by following this workflow. 

You are welcome to come back with more in-depth questions, if you encounter any issues. 

Michael Ginzburg

unread,
Jul 11, 2017, 3:00:48 AM7/11/17
to Google App Engine

Hi.

Yes we are following https://developers.google.com/android-publisher/authorization

Hope we are doing right the first step

Creating an APIs Console project

Because we can’t see for example Services in the left-hand navigation panel.

See screenshot


But we do created         affilatemanager-167005 and  OAuth 2.0 client ID

 

Now we going to step 2

Generating a refresh token

First free points is OK


Point 4 we running following code and getting 401 error


grant_type=authorization_code

code=<the code from the previous step>

client_id=<the client ID token created in the APIs Console>

client_secret=<the client secret corresponding to the client ID>

redirect_uri=<the URI registered with the client ID>

 int responseCode = conn.getResponseCode();


Please advice

George (Cloud Platform Support)

unread,
Jul 13, 2017, 5:01:53 PM7/13/17
to Google App Engine
code=<the code from the previous step> refers to the step described just above the window, namely: "Exchange this code for an access and refresh token pair by sending a POST request to https://accounts.google.com/o/oauth2/token". You need to follow exactly the preceding steps from https://developers.google.com/android-publisher/authorization
Reply all
Reply to author
Forward
0 new messages