Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Why PlayIntegrity api call resulting in Error code :GOOGLE_SERVER_UNAVAILABLE Where am i going wrong ?

See original GitHub issue

Issue Description

Following your example but unfortunately am not getting the token since it is giving an error as GOOGLE_SERVER__UNAVAILABLE. Have done the ground works like Play & Cloud console enablement.

You can check my code:

   protected void onCreate(Bundle savedInstanceState) {

   private void getToken() {
       String nonce = Base64.encodeToString(generateNonce(50).getBytes(),   Base64.URL_SAFE | Base64.NO_WRAP | Base64.NO_PADDING);

       // Create an instance of a manager.
       IntegrityManager integrityManager = IntegrityManagerFactory.create(getApplicationContext());

       // Request the integrity token by providing a nonce.
       Task<IntegrityTokenResponse> integrityTokenResponse = integrityManager.requestIntegrityToken(

       integrityTokenResponse.addOnSuccessListener(new OnSuccessListener<IntegrityTokenResponse>() {
           public void onSuccess(IntegrityTokenResponse integrityTokenResponse) {
               String integrityToken = integrityTokenResponse.token();
               Log.e("Integrity Token", "integrity token from the app" + integrityToken);


       integrityTokenResponse.addOnFailureListener(e -> showErrorDialog("Error getting token from Google. Google said: " + getErrorText(e)));

   private void doIntegrityCheck(String token) {
       AtomicBoolean hasError = new AtomicBoolean(false);

       Observable.fromCallable(() -> {

                   OkHttpClient okHttpClient = new OkHttpClient();
                   Response response = okHttpClient.newCall(new Request.Builder().url("money control url" + "token from backend server" + token).build()).execute();
                   Log.e("Token", "token from the app" + token);

                   if (!response.isSuccessful()) {
                       return "Api request error. Code: " + response.code();

                   ResponseBody responseBody = response.body();
                   if (responseBody == null) {

                       return "Api request error. Empty response";

                   JSONObject responseJson = new JSONObject(responseBody.string());
                   if (responseJson.has("error")) {

                       return "Api request error: " + responseJson.getString("error");

                   if (!responseJson.has("deviceIntegrity")) {


                   return responseJson.getJSONObject("deviceIntegrity").toString();
               }) // Execute in IO thread, i.e. background thread.
               // report or post the result to main thread.
               // execute this RxJava
               .subscribe(new Observer<String>() {
                   public void onSubscribe(Disposable d) {


                   public void onNext(String result) {
                       if (hasError.get()) {
                           if (result.contains("MEETS_DEVICE_INTEGRITY") && result.contains("MEETS_BASIC_INTEGRITY")) {
                              //Here goes my other code


                   public void onError(Throwable e) {


                   public void onComplete() {


 private String getErrorText(Exception e) {
       String msg = e.getMessage();
       if (msg == null) {
           return "Unknown Error";

       //the error code
       int errorCode = Integer.parseInt(msg.replaceAll("\n", "").replaceAll(":(.*)", ""));
       switch (errorCode) {
           case IntegrityErrorCode.API_NOT_AVAILABLE:
               return "API_NOT_AVAILABLE";
           case IntegrityErrorCode.NO_ERROR:
               return "NO_ERROR";
           case IntegrityErrorCode.INTERNAL_ERROR:
               return "INTERNAL_ERROR";
           case IntegrityErrorCode.NETWORK_ERROR:
               return "NETWORK_ERROR";
           case IntegrityErrorCode.PLAY_STORE_NOT_FOUND:
               return "PLAY_STORE_NOT_FOUND";
           case IntegrityErrorCode.PLAY_STORE_ACCOUNT_NOT_FOUND:
               return "PLAY_STORE_ACCOUNT_NOT_FOUND";
           case IntegrityErrorCode.APP_NOT_INSTALLED:
               return "APP_NOT_INSTALLED";
           case IntegrityErrorCode.PLAY_SERVICES_NOT_FOUND:
               return "PLAY_SERVICES_NOT_FOUND";
           case IntegrityErrorCode.APP_UID_MISMATCH:
               return "APP_UID_MISMATCH";
           case IntegrityErrorCode.TOO_MANY_REQUESTS:
               return "TOO_MANY_REQUESTS";
           case IntegrityErrorCode.CANNOT_BIND_TO_SERVICE:
               return "CANNOT_BIND_TO_SERVICE";
           case IntegrityErrorCode.NONCE_TOO_SHORT:
               return "NONCE_TOO_SHORT";
           case IntegrityErrorCode.NONCE_TOO_LONG:
               return "NONCE_TOO_LONG";
           case IntegrityErrorCode.GOOGLE_SERVER_UNAVAILABLE:
               return "GOOGLE_SERVER_UNAVAILABLE";
           case IntegrityErrorCode.NONCE_IS_NOT_BASE64:
               return "NONCE_IS_NOT_BASE64";
               return "Unknown Error";

   private String generateNonce(int length) {
       String nonce = "";
       String allowed = getNonce();
       for (int i = 0; i < length; i++) {
           nonce = nonce.concat(String.valueOf(allowed.charAt((int) Math.floor(Math.random() * allowed.length()))));
       return nonce;

   public native String getNonce();

   static {

Issue Analytics

  • State:closed
  • Created 4 months ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1nikolascommented, Sep 13, 2022

The json should be in the server not the app

1nikolascommented, Sep 13, 2022

Okay I think I remembered. Is your app on Google Play right now?

Read more comments on GitHub >

github_iconTop Results From Across the Web

why PlayIntegrity api call resulting in error code - Issue Tracker
Hi The pacakge name is: com.moneycontrol.handheld. Now there is no more error like GOOGLE SERVER UNAVAILABLE. I am receiving API_NOT_AVAILABLE ...
Read more >
Why PlayIntegrity api call resulting in Error code - java
You can find this in Project info in the Google Cloud Console. So the code should be like this: IntegrityTokenRequest.builder() .setNonce(nonce) ...
Read more >
IntegrityErrorCode - Android Developers
No Play Store account is found on device. Note that the Play Integrity API now supports unauthenticated requests. This error code is used ......
Read more >
10 Error Status Codes When Building APIs For The First Time ...
The 400 Bad Request error message is one of the most generic HTTP status codes. It implies that you did not correctly format...
Read more >
[DISCUSSION] Play Integrity API - XDA Forums
Ideally, I think this should be scoped to Play Integrity code by identifying methods it calls near the beginning and end of integrity...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found