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