Re: Google Play Developer API connection issues

365 views
Skip to first unread message
Message has been deleted

George (Cloud Platform Support)

unread,
Jun 23, 2017, 3:26:40 PM6/23/17
to Google App Engine
Hello Michael, 

How did you get the value for the token for KEY_AUTHTOKEN; in other words, is the "myAccount" value correct? 

For the initial configuration, did you follow the relevant documentation page at "Authorization"? You can follow simply the API-specific authorization process at "Oath 2.0 Playground". 

To read detailed information on user subscriptions, you may consider checking the author's own reply to the "Unable to get the subscription information from Google Play Android Developer API" question on stackoverflow. 

Michael Ginzburg

unread,
Jul 3, 2017, 4:19:16 AM7/3/17
to Google App Engine

Hi, thank you very much for your reply.

See below our answers the concerns


Our main problem is “How to get token?”


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

We also try your example with P12 file instead of json on stackoverflow and we can’t understand where token come from


AndroidPublisher.Purchases.Get get = pub.purchases().get(

    APPLICATION_NAME,

    PRODUCT_ID,

    token);

SubscriptionPurchase subscription = get.execute();In all previous code token have not been received

 There are 2 other answers on this stackoverflow question – no one work for us.


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

“How did you get the value for the token for KEY_AUTHTOKEN; in other words, is the "myAccount" value correct?”


We assume "myAccount" value is correct, because it’s our main account we are logging in with this account. This account is added to the device where an app is running.This is owner account and has all permissions


“For the initial configuration, did you follow the relevant documentation page at "Authorization"? You can follow simply the API-specific authorization process at "Oath 2.0 Playground".”


When we follow simply the API-specific authorization process at "Oath 2.0 Playground, then we do revive


{

  "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


//oauth2/v4/token

We try both but getting the same error

Here is the app code


https://accounts.google.com

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()));

Michael Ginzburg

unread,
Jul 3, 2017, 4:20:05 AM7/3/17
to Google App Engine


On Friday, 23 June 2017 16:17:20 UTC+3, Michael Ginzburg wrote:

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?

 

Below is our experience

 

When I use authScope =  "https://www.googleapis.com/auth/androidpublisher";

 (took it from Google Example)

            // private static final String authScope = "https://www.googleapis.com/auth/androidpublisher";

am.getAuthToken(myAccount,authScope,options,this,new OnTokenAcquired(),new Handler(new OnError()));

private class OnTokenAcquired implements AccountManagerCallback<Bundle> {
   
@Override
   
public void run(AccountManagerFuture<Bundle> accountManagerFuture) {
        try {
            Bundle bundle = accountManagerFuture.getResult();
            String token = bundle.getString(AccountManager.KEY_AUTHTOKEN);
        }
catch ( Exception ae ) {
            Log.e(
TAG, "OnTokenAcquired Exception=" + ae.getMessage(), ae);
        }
    }
}

I can’t get the token, because I get exception below

 

OnTokenAcquired Exception=Unknown

                                                                        android.accounts.AuthenticatorException: Unknown
                                                                            at android.accounts.AccountManager.convertErrorToException(AccountManager.java:2213)
                                                                            at android.accounts.AccountManager.-wrap0(AccountManager.java)
                                                                            at android.accounts.AccountManager$AmsTask$Response.onError(AccountManager.java:2056)
                                                                            at android.accounts.IAccountManagerResponse$Stub.onTransact(IAccountManagerResponse.java:69)
                                                                            at android.os.Binder.execTransact(Binder.java:565)

 

When I use authScope = "Manage your tasks";
 (took it from another Google Example)

private static final String authScope = "Manage your tasks";

I'm receiving token, but on ProductPurchase product = purchases.products().get(PACKAGE_NAME, TEST_SKU, token).execute();

 

I am getting getProducts Exception=400 Bad Request

getProducts Exception=400 Bad Request
                                                                      {
                                                                        "code" : 400,
                                                                        "errors" : [ {
                                                                          "domain" : "global",
                                                                          "message" : "Invalid Value",
                                                                          "reason" : "invalid"
                                                                        } ],
                                                                        "message" : "Invalid Value"
                                                                      }
                                                                      com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 Bad Request
                                                                      {
                                                                        "code" : 400,
                                                                        "errors" : [ {
                                                                          "domain" : "global",
                                                                          "message" : "Invalid Value",
                                                                          "reason" : "invalid"
                                                                        } ],
                                                                        "message" : "Invalid Value"
                                                                      }
                                                                          at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
                                                                          at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
                                                                          at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(AbstractGoogleClientRequest.java:321)
                                                                          at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
                                                                          at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
                                                                          at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
                                                                          at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)

Reply all
Reply to author
Forward
0 new messages