このガイドに従って、Google App EngineのリモートAPIに接続できません:私はガイドをfolowedとweb.xmlを変更した私は私のローカルマシンから自分のデータにアクセスやろうとしています
https://cloud.google.com/appengine/docs/java/tools/remoteapi
、展開コードは、私は例外を取得「のgcloudのinit」コマンドを実行し、クラウドSDKをインストールしてプロジェクトを選択したが、サンプルコードを実行するときに:ここで
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
は私のコードです:
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();
}
}
}
誰でもこの問題を解決する方法がありますか?
UPDATE:
今資格が固定されているようです。サーバーは、web.xml内のリモートAPIを持っていませんが、私はそれを行っているときに発生する。このpostによる
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)
:しかし今、スタックトレースは、302を返します。サーバー側で必要なものは何ですか?
JSONを使用する方法上の任意のヒントをもっと読みますか?チュートリアルやサンプルコードのように?私が見つけることができる唯一のサンプルはgcloudライブラリを使用し、appengineは使用しません。 –
RemoteApiOptions raoptions = new RemoteApiOptions() .server( "my-module-dot-my-project.appspot.com"、443) .useServiceAccountCredential( "my-service-account-id"、 "my-service-account-id"、 "my-service-account-id" .p12 "); – varun
http://varunsweblog.appspot。com/posts/how-to-use-google-appengine-remote-api-for-java – varun