Cannot connect to Google App Engine Remote API

140 views
Skip to first unread message

Theis Borg via StackOverflow

unread,
Sep 30, 2016, 7:15:06 AM9/30/16
to google-appengin...@googlegroups.com

I am trying to do access my data from my local machine by following this guide:

https://cloud.google.com/appengine/docs/java/tools/remoteapi

I have folowed the guide and changed the web.xml, deployed the code, installed the cloud sdk, run the "gcloud init" command and selected the project but when running the sample code I get an exception:

Exception in thread "main" java.lang.RuntimeException: Failed to acquire Google Application Default credential.
    at com.google.appengine.tools.remoteapi.RemoteApiOptions.useApplicationDefaultCredential(RemoteApiOptions.java:169)
    at androidlost_remote.RemoteTest.main(RemoteTest.java:14)
Caused by: java.io.IOException: The Application Default Credentials are not available. They are available if running on Google App Engine, Google Compute Engine, or Google Cloud Shell. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials. See https://developers.google.com/accounts/docs/application-default-credentials for more information.
    at com.google.appengine.repackaged.com.google.api.client.googleapis.auth.oauth2.DefaultCredentialProvider.getDefaultCredential(DefaultCredentialProvider.java:98)
    at com.google.appengine.repackaged.com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:213)
    at com.google.appengine.repackaged.com.google.api.client.googleapis.auth.oauth2.GoogleCredential.getApplicationDefault(GoogleCredential.java:191)
    at com.google.appengine.tools.remoteapi.RemoteApiOptions.useApplicationDefaultCredential(RemoteApiOptions.java:164)
    ... 1 more

Here is my code:

import java.io.IOException;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
import com.google.appengine.tools.remoteapi.RemoteApiOptions;

public class RemoteTest {

    public static void main(String[] args) throws IOException {
        RemoteApiOptions options = new RemoteApiOptions().server("myappid-hr.appspot.com", 443).useApplicationDefaultCredential();
        RemoteApiInstaller installer = new RemoteApiInstaller();
        installer.install(options);
        try {
            DatastoreService ds = DatastoreServiceFactory.getDatastoreService();
            System.out.println("Key of new entity is " + ds.put(new Entity("Hello Remote API!")));
        } finally {
            installer.uninstall();
        }
    }
}

Anyone have an idea on how to fix this?



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/39790201/cannot-connect-to-google-app-engine-remote-api

Carter Brainerd via StackOverflow

unread,
Sep 30, 2016, 8:50:32 AM9/30/16
to google-appengin...@googlegroups.com

Well, let's break down the error code. The first line of the error code: Failed to acquire Google Application Default credential. Tells you what's not working right (couldn't get the GAD credential).

The next line of note is: at androidlost_remote.RemoteTest.main(RemoteTest.java:14). This tells you that the error was caused on line 14 of the remoteTest class.

Line 14 is installer.install(options);. This points back to your RemoteApiOptions options variable. Be sure that the .options() arguements point to the correct webserver and port.

Back to the error code now, line 4 straight up tells you why it happened: a java.io.IOException. It says this happened because They are available if running on Google App Engine, Google Compute Engine, or Google Cloud Shell. All of which I'm guessing you don't have. So the error code tells you what you need to do and where to go for help. You need to install Google App Engine, Google Compute Engine, or Google Cloud Shell.

Either you install one/all of those, or the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials

From line 4 of the error code: https://developers.google.com/accounts/docs/application-default-credentials for more information



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/39790201/cannot-connect-to-google-app-engine-remote-api/39791798#39791798

varun via StackOverflow

unread,
Sep 30, 2016, 9:55:08 AM9/30/16
to google-appengin...@googlegroups.com

Create a new Credential, give it right IAM access, download the json and finally use it before using the api. :)



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/39790201/cannot-connect-to-google-app-engine-remote-api/39793187#39793187

Theis Borg via StackOverflow

unread,
Oct 3, 2016, 6:40:07 PM10/3/16
to google-appengin...@googlegroups.com

UPDATE:

Now the credential seems to be fixed. However now the stacktrace returns a 302:

Exception in thread "main" com.google.appengine.repackaged.com.google.api.client.http.HttpResponseException: 302 Found
    at com.google.appengine.repackaged.com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1070)
    at com.google.appengine.tools.remoteapi.OAuthClient.get(OAuthClient.java:64)
    at com.google.appengine.tools.remoteapi.RemoteApiInstaller.getAppIdFromServer(RemoteApiInstaller.java:413)
    at com.google.appengine.tools.remoteapi.RemoteApiInstaller.loginImpl(RemoteApiInstaller.java:376)
    at com.google.appengine.tools.remoteapi.RemoteApiInstaller.login(RemoteApiInstaller.java:337)
    at com.google.appengine.tools.remoteapi.RemoteApiInstaller.install(RemoteApiInstaller.java:173)
    at androidlost_remote.RemoteTest3.main(RemoteTest3.java:16)

According to this post it occurs when the server has not got the remote api in web.xml but I have done that. Anything else I need on the server side?

varun via StackOverflow

unread,
Oct 4, 2016, 6:40:05 AM10/4/16
to google-appengin...@googlegroups.com

Create a new Credential, give it right IAM access, download the json and finally use it before using the api. :)

read more here



Please DO NOT REPLY directly to this email but go to StackOverflow:
http://stackoverflow.com/questions/39790201/cannot-connect-to-google-app-engine-remote-api/39793187#39793187
Reply all
Reply to author
Forward
0 new messages