我正在嘗試使用遠程API從另一個GAE項目訪問一個應用程序的DataStore。 我使用下面的代碼:GAE HttpResponseException:401
String serverString = "http://example.com";//this should be the target appengine
RemoteApiOptions options;
if (serverString.equals("localhost")) {
options = new RemoteApiOptions().server(serverString, 8080).useDevelopmentServerCredential();
} else {
options = new RemoteApiOptions().server(serverString, 80).useApplicationDefaultCredential();
}
RemoteApiInstaller installer = new RemoteApiInstaller();
installer.install(options);
datastore = DatastoreServiceFactory.getDatastoreService();
try {
results = datastore.get(KeyFactory.createKey("some key"));
} catch (EntityNotFoundException e) {
e.printStackTrace();
return null;
}
當我運行這個地方,我在installer.install(options);
得到一個NullPointerException。 和部署時,從錯誤報告上看到AppEngine上的錯誤是:HttpResponseException: 401 You must be logged in as an administrator, or access from an approved application.
話雖這麼說,我做了的follwing代碼Java小應用程序:
String serverString = "http://example.com";//same string as the one used in the above code
RemoteApiOptions options;
if (serverString.equals("localhost")) {
options = new RemoteApiOptions().server(serverString, 8080).useDevelopmentServerCredential();
} else {
options = new RemoteApiOptions().server(serverString, 80).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!")));
,這一次的作品!你好新增Remote API實體。
無法測試這個呢,卡在這裏https://stackoverflow.com/questions/44114233/access-files-in-gae-project –