4

Google Cloud Endpoint から始めて、三目並べの例 ( https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-javaを参照)

次に、最新の Android Ellipse プラグインで Ellipse を介して「AppEngine Connected Android Project」を作成します ( 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 例外の場合、これを追加します。

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

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

API エクスプローラー https://[your-app-id].appspot.com/_ah/api/explorer を使用してテストします。[your-app-id] を特定のアプリケーション 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"
 }
}

ダウンロードしたチックタックトーアプリケーション (Google Dev Rel に感謝) でエクスプローラーを試してみました: 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-authenticate: GoogleLogin realm="https://www.google.com/accounts/ClientLogin", service="xapi" and

一般に、「App Engine Connected Android Project」で生成されたエンドポイントに認証を追加するにはどうすればよいでしょうか?

Web アプリケーション、Android クライアント、または iOS クライアントから、API エクスプローラーからテストできますか?

4

1 に答える 1

2

「一般的に、「App Engine Connected Android Project」で生成されたエンドポイントに認証を追加するにはどうすればよいですか?」

そのための手順は次のとおりです:
https://developers.google.com/appengine/docs/java/endpoints/consume_android#making-authenticated-calls

また、iOS および Javascript の手順も表示されます (以降のページ)。

サーバー側では、ユーザー オブジェクトをエンドポイント メソッドの最初のパラメーターとして追加する必要があります。

あなたの他の質問に対する答えがわかりません。

于 2013-04-02T14:18:34.903 に答える