Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8626215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:58:17+00:00 2026-06-12T07:58:17+00:00

I’trying to use Google APIs Client Library for Java to get information about user’s

  • 0

I’trying to use Google APIs Client Library for Java to get information about user’s subscriptions purchased in my android app. Here is how I’m doing for now:

HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
JsonFactory JSON_FACTORY = new JacksonFactory();

GoogleCredential credential = new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
                    .setJsonFactory(JSON_FACTORY)
                    .setServiceAccountId(GOOGLE_CLIENT_MAIL)
                    .setServiceAccountScopes("https://www.googleapis.com/auth/androidpublisher")
                    .setServiceAccountPrivateKeyFromP12File(new File(GOOGLE_KEY_FILE_PATH))
                    .build();

Androidpublisher publisher = new Androidpublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).
                    setApplicationName(GOOGLE_PRODUCT_NAME).
                    build();

Androidpublisher.Purchases purchases = publisher.purchases();
Get get = purchases.get("XXXXX", subscriptionId, token);
SubscriptionPurchase subscripcion = get.execute(); //Exception returned here

GOOGLE_CLIENT_MAIL is the email address from API Access from the Google Console.
GOOGLE_KEY_FILE_PATH is the p12 file downloaded from the API Access.
GOOGLE_PRODUCT_NAME is the product name from the branding information.
In Google APIS Console the Service “Google Play Android Developer API” is enabled.

What I’m getting is:

{
  "code" : 401,
  "errors" : [ {
    "domain" : "androidpublisher",
    "message" : "This developer account does not own the application.",
    "reason" : "developerDoesNotOwnApplication"
  } ],
  "message" : "This developer account does not own the application."
}

I really appreciate your help for this issue…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:58:18+00:00Added an answer on June 12, 2026 at 7:58 am

    I got it working! The steps I followed:

    Prerequisite

    Before start, we need to generate a refresh token. To do this first we have to create an APIs console project:

    1. Go to the APIs Console and log in with your Android developer
      account (the same account used in Android Developer Console to upload the APK).
    2. Select Create project.
    3. Go to Services in the left-hand navigation panel.
    4. Turn the Google Play Android Developer API on.
    5. Accept the Terms of Service.
    6. Go to API Access in the left-hand navigation panel.
    7. Select Create an OAuth 2.0 client ID:
      • On the first page, you will need to fill in the product name, but a
        logo is not required.
      • On the second page, select web application and set the redirect URI
        and Javascript origins. We will use it later the redirect URI.
    8. Select Create client ID. Keep in mind the Client ID and the Client secret, we will use them later.

    So, now we can generate the refresh token:

    1. Go to the following URI (note that the redirect URI must match the value entered in the client ID exactly, including any trailing backslashes):

    https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=REDIRECT_URI&client_id=CLIENT_ID

    1. Select Allow access when prompted.
    2. The browser will be redirected to your redirect URI with a code parameter, which will look similar to 4/eWdxD7b-YSQ5CNNb-c2iI83KQx19.wp6198ti5Zc7dJ3UXOl0T3aRLxQmbwI. Copy this value.

    Create a main class with:

    public static String getRefreshToken(String code)
    {
    
        HttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost("https://accounts.google.com/o/oauth2/token");
        try 
        {
            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(5);
            nameValuePairs.add(new BasicNameValuePair("grant_type",    "authorization_code"));
            nameValuePairs.add(new BasicNameValuePair("client_id",     GOOGLE_CLIENT_ID));
            nameValuePairs.add(new BasicNameValuePair("client_secret", GOOGLE_CLIENT_SECRET));
            nameValuePairs.add(new BasicNameValuePair("code", code));
            nameValuePairs.add(new BasicNameValuePair("redirect_uri", GOOGLE_REDIRECT_URI));
            post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    
            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());
            String refreshToken = json.getString("refresh_token");                      
            return refreshToken;
        }
        catch (Exception e) { e.printStackTrace(); }
    
        return null;
    }
    

    GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET and GOOGLE_REDIRECT_URI are the previously values.

    Finally, we have our refresh token! This value does not expire, so we can store in some site, like a property file.

    Accessing to Google Play Android Developer API

    1. Getting the access token. We will need our previosly refresh token:

      private static String getAccessToken(String refreshToken){
      
      HttpClient client = new DefaultHttpClient();
      HttpPost post = new HttpPost("https://accounts.google.com/o/oauth2/token");
      try 
      {
          List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
          nameValuePairs.add(new BasicNameValuePair("grant_type",    "refresh_token"));
          nameValuePairs.add(new BasicNameValuePair("client_id",     GOOGLE_CLIENT_ID));
          nameValuePairs.add(new BasicNameValuePair("client_secret", GOOGLE_CLIENT_SECRET));
          nameValuePairs.add(new BasicNameValuePair("refresh_token", refreshToken));
          post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
      
          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());
          String accessToken = json.getString("access_token");
      
          return accessToken;
      
      }
      catch (IOException e) { e.printStackTrace(); }
      
      return null;
      

      }

    2. Now, we can access to the Android API. I’m interesting in the expiration time of a subscription, so:

      private static HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
      private static JsonFactory JSON_FACTORY = new com.google.api.client.json.jackson2.JacksonFactory();
      
      private static Long getSubscriptionExpire(String accessToken, String refreshToken, String subscriptionId, String purchaseToken){
      
      try{
      
          TokenResponse tokenResponse = new TokenResponse();
          tokenResponse.setAccessToken(accessToken);
          tokenResponse.setRefreshToken(refreshToken);
          tokenResponse.setExpiresInSeconds(3600L);
          tokenResponse.setScope("https://www.googleapis.com/auth/androidpublisher");
          tokenResponse.setTokenType("Bearer");
      
          HttpRequestInitializer credential =  new GoogleCredential.Builder().setTransport(HTTP_TRANSPORT)
                  .setJsonFactory(JSON_FACTORY)
                  .setClientSecrets(GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET)
                  .build()
                  .setFromTokenResponse(tokenResponse);
      
          Androidpublisher publisher = new Androidpublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential).
                  setApplicationName(GOOGLE_PRODUCT_NAME).
                  build();
      
          Androidpublisher.Purchases purchases = publisher.purchases();
          Get get = purchases.get(GOOGLE_PACKAGE_NAME, subscriptionId, purchaseToken);
          SubscriptionPurchase subscripcion = get.execute();
      
          return subscripcion.getValidUntilTimestampMsec();
      
      }
      catch (IOException e) { e.printStackTrace(); }
      return null;
      

      }

    And that’s all!

    Some steps are from https://developers.google.com/android-publisher/authorization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.