2015-01-04 89 views
0

好吧,我試圖失敗連接到遠程數據存儲和填充使用這裏列出的步驟,我的本地機器:https://cloud.google.com/appengine/docs/java/tools/remoteapi#Configuring_Remote_API_on_the_ClientGAE遠程API - 無法連接

public static void main(String[] args) { 

    String username = "[email protected]"; 
    String password = "mygmailpassword"; 
    RemoteApiOptions options = new RemoteApiOptions() 
     .server("myappname.appspot.com", 443) 
     .credentials(username, password); 
    RemoteApiInstaller installer = new RemoteApiInstaller(); 
    installer.install(options); 

    try {  
     DatastoreService ds = DatastoreServiceFactory.getDatastoreService(); 
     ... 

我得到在安裝404 .install(選項): java.io.IOException:無法從遠程api獲取appId;狀態代碼= 404 我在這裏錯過了什麼嗎?我在我的web.xml中啓用了遠程API,並部署到GAE。我是該項目的所有者。

回答

2

在本地運行您的服務(啓用遠程API)並嘗試使用'localhost'和8888(端口)運行相同的代碼,並檢查您的代碼是否可以訪問本地運行的服務。你的代碼看起來不錯。有兩種可能性 - 1. RemoteApi未正確啓用。 2.應用程序名稱拼寫不正確。

除此之外,我還可以使用下面的代碼來訪問遠程API -

 installer.install(options); 
     try { 
      // Update the options with reusable credentials so we can skip 
      // authentication on subsequent calls. 
      options.reuseCredentials(username, installer.serializeCredentials()); 
     } finally { 
      installer.uninstall(); 
     } 

但是,不應該給你你要的錯誤。

+0

如果您得到404這意味着您的應用程序未提供服務,遠程API未正確配置(沒有端點),或者您錯誤地拼寫應用程序名稱。 – Adam

1

我意識到這有點晚了,但是當我在Google上搜索時發現了這個,因爲我有類似的問題,我自己解決了這個問題。對我來說,問題在於我的AppEngine應用程序服務於遠程API,它是一個python應用程序,python文檔指示配置遠程api端點爲/remoteapi.*

但是,我的遠程api客戶端是一個java應用程序,顯然是遠程a​​pi調用它的結果,如下所示:/ remote_api。所以添加到服務器路由配置(在我的情況下app.yaml)解決了這個問題。另請注意,如果你的服務的AppEngine應用遠程API不是默認的模塊中,該URL應該像我的模塊名稱 -dot- 我的項目 .appspot.com的

而且,您應該使用useApplicationDefaultCredential()而不是憑證(),因此不推薦使用。