Connecting to remote api returns 302

404 views
Skip to first unread message

contact androidlost

unread,
Sep 30, 2016, 5:44:34 PM9/30/16
to Google App Engine
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 changed the web.xml, installed the cloud SDK and ran "gcloud init" and selected the app.

Here is my test code:

package androidlost_remote;

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("airtellost.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();
       
}
   
}
}

But all I get is an exception:

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
.RemoteTest.main(RemoteTest.java:16)

I have no security-constraints in my web.xml.

Any suggestions on how to avoid this exception?

Alex (Cloud Platform Support)

unread,
Oct 6, 2016, 11:17:02 AM10/6/16
to Google App Engine

Hi Jesse,


Please note that this type of question is more appropriate for Stack Overflow which we regularly monitor as other types of stack exchange services and which would increase your chances to get a faster answer due to its larger audience.


According to your exception log, the issue comes from line 16 of RemoteTest.java. So you may want to look at the useApplicationDefaultCredential() method and make sure that the application default credentials are set appropriately on your machine. More specifically, try using your identity as a proxy to test code calling the API with “gcloud beta auth application-default login” command.


Alternatively, you could use a manually exported service account p12 key, with useServiceAccountCredential(serviceAccountId, p12PrivateKeyFile) method and for more information on how to generate a p12 format follow the instructions here.


Let me know if that works for you.

Reply all
Reply to author
Forward
0 new messages