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 8644143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:13:24+00:00 2026-06-12T12:13:24+00:00

in a nutshell: Can I work with the Google Play Android Developer API from

  • 0

in a nutshell:
Can I work with the Google Play Android Developer API from server-side without providing any app in the play store?

Background:
I’m working on a project which provides apps with monthly subscriptions. The coresponding data of each subscription (purchase token, date etc) gets stored in the backend database.
Now I want to create a cronjob that iterates through each of these datasets.And for each subscription I’d like to contact the Google API to retrieve the information if the subscription is still valid or not, and update our database corresponding to the responsed status.

For the backend logic I use the google-api-java-client library.

To either cancel or verify subscriptions I need to authenticate myself with OAuth2 before.
Been there, done that.

new GoogleCredential.Builder()
    .setTransport(HTTP_TRANSPORT)
    .setJsonFactory(JSON_FACTORY)
    .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
    .setServiceAccountScopes("https://www.googleapis.com/auth/androidpublisher") // $1
    .setServiceAccountPrivateKeyFromP12File(new File(filePath))
    .setClientSecrets(CLIENT_ID, CLIENT_SECRET) // $2
    .build();

$1: I don’t know if the given account scope is valid. Because I just could find this value in a very few examples, but neither in this overview nor in the google playground

$2 I guess this is necessary, even though I found a lot of example which did not provide this information.

But, unfortunately, I can’t see any differences when I provide invalid data (like wrong email or private key).

Questions

  • How can i verify that the GoogleCredential is correct?
  • May I just see it in the next steps, like contacting ie the androidpublisher API?

In the next step I try to get purchase status of a subscription:

Androidpublisher publisher = new Androidpublisher.Builder(HTTP_TRANSPORT, JSON_FACTORY, credential)
                               .setApplicationName(GOOGLE_PRODUCT_NAME) // $1                
                               .build();
Androidpublisher.Purchases purchases = publisher.purchases();
Androidpublisher.Purchases.Get get = purchases.get("android.test.purchased", "monthly001", "mytoken"); // $2
SubscriptionPurchase subscripcion = get.execute(); 

$1: My dummy product name from the API console -> API Access

$2: Beside the fact, that the androidpush API does not allow contacting it via service accounts, but only via web server applications auth flow, I don’t have any clue what to insert in the parameter of the get- method.

Here’s the API:
https://developers.google.com/android-publisher/v1/purchases/get

Questions

  • What is the package name and what is the subscriptionId in this context?
  • Where do I get/set these values?

After reading this document I know there is a way to to deal with fake/static responses. But I can’t read anywhere if this is also possible for subscriptions, or just for in-app-billings on mobile devices only.

I’m wondering anyway why/if there is any easy way of developing with a sandbox or s.th. simliar.

I still have the feeling that I’m just missing a big part to understand how the things should work.
Maybe someone of you can give me a hint how to proceed at this place or may say me where i’m wrong.

Kind regards,

Christopher

  • 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-12T12:13:25+00:00Added an answer on June 12, 2026 at 12:13 pm

    I could now figure out most of my previous understanding problems.

    =1= GENERATE AUTHORIZATION URL

    String authorizeUrl = new GoogleAuthorizationCodeRequestUrl(googleClientId,callbackUrl,"https://www.googleapis.com/auth/androidpublisher").build()    
    // See why: http://stackoverflow.com/questions/8433990/when-authenticating-with-oauth-and-youtube-always-get-error-invalid-grant-on
    authorizeUrl += "&approval_prompt=force&access_type=offline"
    

    =2= AUTHENTICATE

    Since the server-webflow is not working for the androidpublisher API the customer must now call the URL generated in (1) manually.

    =3= CALLBACK

    The google callback should process the next steps. The callback contains the parameter “code” which we have to use.

    =4= REQUEST AUTH-TOKEN

        // Build the HTTP parameter
        Map<String,String> params = [:]
        params.put("grant_type", "authorization_code")
        params.put("code", code.encodeAsURL())
        params.put("client_id", customer.googleClientId.encodeAsURL())
        params.put("client_secret", customer.googleClientSecret.encodeAsURL())
        params.put("redirect_uri", getCallbackUrl().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)
    
        // Map result
        OAuth2Result oAuth2Result = new OAuth2Result()
        oAuth2Result.accessToken = jsonResult.getAt("access_token")
        oAuth2Result.refreshToken = jsonResult.getAt("refresh_token")
        oAuth2Result.ttlSeconds = Integer.parseInt(jsonResult.getAt("expires_in").toString())
        oAuth2Result.tokenType = jsonResult.getAt("token_type") 
    

    =5= REQUEST REFRESH TOKEN

        // Build the HTTP parameter
        Map<String,String> params = [:]
        params.put("grant_type", "refresh_token")
        params.put("refresh_token", this.customer.googleRefreshToken.encodeAsURL())
        params.put("client_id", customer.googleClientId.encodeAsURL())
        params.put("client_secret", customer.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)
    
        // Map result
        OAuth2Result oAuth2Result = new OAuth2Result()
        oAuth2Result.accessToken = jsonResult.getAt("access_token")
        oAuth2Result.refreshToken = jsonResult.getAt("refresh_token")
        oAuth2Result.ttlSeconds = Integer.parseInt(jsonResult.getAt("expires_in").toString())
        oAuth2Result.tokenType = jsonResult.getAt("token_type")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a nutshell we're unable to get reasonable scrolling performance from any kind of
In a nutshell: what sort of applications would be benefit most from the dashboard
I have a iOS app that, in a nutshell, uses a UITableView and a
One can use poll/select when writing a server that can service multiple clients all
Nutshell: I launch a thread from my form, then some time later use the
SHORT VERSION: How can I load classes during runtime from a bundle, when those
Related to this question: Use with XMLVM to convert android app to iphone app
In a nutshell I'm writing a Symfony2 / Doctrine2 app and have installed and
Problem: I'm writing an Android app, and one of its features requires Open Accessory
In a nutshell what my program does is: it executes and takes user input

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.