3

與谷歌雲端點開始,井字例子(見https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-java如何向Google雲終端添加身份驗證?

然後,創建一個「AppEngine上連接的Android項目」,在最新的Android橢圓插件通過橢圓(見https://developers.google.com/eclipse/docs/endpoints-androidconnected-gae

現在這個創建沒有驗證的端點。

// @Api(name = "messageEndpoint") 
//NO AUTHENTICATION; OPEN ENDPOINT! 

現在嘗試使用tic tac toe應用程序添加身份驗證作爲示例。

@Api(name = "messageEndpoint", 
version = "v1", 
clientIds = {Ids.WEB_CLIENT_ID, Ids.ANDROID_CLIENT_ID, Ids.IOS_CLIENT_ID, com.google.api.server.spi.Constant.API_EXPLORER_CLIENT_ID}, 
audiences = {Ids.ANDROID_AUDIENCE} 

在OAuth的異常的情況下,補充一點:使用API​​探險

//public void sendMessage(@Named("message") String message) 
    //throws IOException { 

public void sendMessage(@Named("message") String message) 
    throws OAuthRequestException,IOException { 

和測試,https://開頭[您的應用ID] .appspot.com訪問/ _ah/api/explorer,我用我的特定應用程序ID替換了[your-app-id]。

POST https://[your-app-id].appspot.com/_ah/api/messageEndpoint/v1/sendMessage/test 
X-JavaScript-User-Agent: Google APIs Explorer 

503 Service Unavailable 


cache-control: private, max-age=0 
content-encoding: gzip 
content-length: 193 
content-type: application/json; charset=UTF-8 
date: Mon, 01 Apr 2013 22:57:17 GMT 
expires: Mon, 01 Apr 2013 22:57:17 GMT 
server: GSE 

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "backendError", 
    "message": "java.lang.NoClassDefFoundError: Could not initialize class com.brooklynmarathon.citysync.endpoints.EMF" 
    } 
    ], 
    "code": 503, 
    "message": "java.lang.NoClassDefFoundError: Could not initialize class com.brooklynmarathon.citysync.endpoints.EMF" 
} 
} 

我試圖用我下載(感謝谷歌開發版本)和內建這裏上傳井字應用程序的資源管理器:https://brooklynmarathon.appspot.com/_ah/api/explorer

當我嘗試訪問成績榜,我看到:

GET https://brooklynmarathon.appspot.com/_ah/api/tictactoe/v1/score 

X-JavaScript-User-Agent: Google APIs Explorer 


Response 


401 Unauthorized 

- Hide headers - 

cache-control: private, max-age=0 
content-encoding: gzip 
content-length: 193 
content-type: application/json; charset=UTF-8 
date: Tue, 02 Apr 2013 01:14:40 GMT 
expires: Tue, 02 Apr 2013 01:14:40 GMT 
server: GSE 
www-authenticate: GoogleLogin realm="https://www.google.com/accounts/ClientLogin", service="xapi" 

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "required", 
    "message": "com.google.appengine.api.oauth.OAuthRequestException: Invalid user.", 
    "locationType": "header", 
    "location": "Authorization" 
    } 
    ], 
    "code": 401, 
    "message": "com.google.appengine.api.oauth.OAuthRequestException: Invalid user." 
} 
} 

我的問題是爲什麼井字例如具有頭:「WWW驗證:的GoogleLogin境界=」 https://www.google.com/accounts/ClientLogin」,服務=‘XAPI’和

一般來說,我們如何向「App Engine Connected Android Project」生成的端點添加身份驗證?

從Web應用程序,Android客戶端或iOS客戶端,我們可以從api資源管理器中測試它嗎?

+0

您使用了什麼值用於'ID。* _ CLIENT_ID'? – Drux

+0

+ Drux感謝您的詢問,但是我繼續使用了可用的python解決方案,因此無需回答此問題。 –

回答

1

「一般來說,我們如何向」App Engine Connected Android Project「生成的端點添加身份驗證?」

做這件事是這裏的說明:
https://developers.google.com/appengine/docs/java/endpoints/consume_android#making-authenticated-calls

您也將看到的iOS和Javascript有指令(在隨後的頁面)。

在服務器端,您需要添加User對象作爲端點方法的第一個參數。

我不知道你的其他問題的答案。

+0

謝謝湯姆。我錯過了來自tic tac toe示例的User參數,所以我添加了它,仍然看到錯誤,例如「com.google.api.server.spi.SystemService invokeServiceMethod:null java.lang.ExceptionInInitializerError」感謝您的幫助。如果您或任何人有關於調試錯誤(如這些和測試)的最佳實踐的建議,請發佈它們。 –

+0

我認爲錯誤是Android運行時錯誤。我可以建議的是,這表明您在調用服務之前沒有完成所需的一切。你需要發佈更多的信息,它可能應該是一個單獨的問題。 – Tom