與谷歌雲端點開始,井字例子(見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資源管理器中測試它嗎?
您使用了什麼值用於'ID。* _ CLIENT_ID'? – Drux
+ Drux感謝您的詢問,但是我繼續使用了可用的python解決方案,因此無需回答此問題。 –