2016-07-05 7 views
0

Google Cloud Endpoints Javaサーバーの一例であるGoogle App Engineにこのレポを配備しました。 https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-java郵便配達員からJavaサーバー上のGoogleクラウドエンドポイントをテストできません

アプリが正常に機能しました。 Google API Explorerを使用してREST API呼び出しをテストできました。ただし、Postman(RESTクライアントのChrome拡張機能)などの外部ツールを使用して、このアプリへのREST APIコールをテストしたいと思います。

私はGoogleからアクセストークンを取得することに成功しました。しかし、Postmanや一般のブラウザから電話をかけたとき、アプリは「Invalid User」というエラーでAPI呼び出しを拒否し続けました。 nullを返した入力ユーザーをログに記録しようとしました。

以下のスニペットは、私が到達しようとしていたREST APIです。メソッドのパラメータであるUserは、GoogleAppEngineAuthenticatorから取得され、どのように動作するかはわかりません。

/** 
* Provides the ability to query for a collection of Score entities. 
* 
* @param limit 
*   maximum number of entries to return 
* @param order 
*   how the entries should be ordered 
* @param user 
*   object representing the current user making requests 
* @return the collection of Score entities 
* @throws OAuthRequestException 
*    if the token included in the request is invalid, the client 
*    ID included in the token is not in the list of allowed 
*    clientIds, or the audience included in the token is not in 
*    the list of allowed audiences. 
* @throws IOException 
*/ 
@ApiMethod(name = "scores.list") 
@SuppressWarnings("unchecked") 
public List<Score> list(@Nullable @Named("limit") String limit, @Nullable @Named("order") String order, User user) 
     throws OAuthRequestException, IOException { 
    System.out.println(user); 
    PersistenceManager pm = getPersistenceManager(); 
    Query query = pm.newQuery(Score.class); 
    if (order != null) { 
     if (order.equals(WHEN)) { 
      query.setOrdering("played desc"); 
     } else if (order.equals(OUTCOME)) { 
      query.setOrdering("outcome asc"); 
     } 
    } else { 
     query.setOrdering("played desc"); 
    } 

    if (user != null) { 
     query.setFilter("player == userParam"); 
     query.declareParameters("com.google.appengine.api.users.User userParam"); 
    } else { 
     throw new OAuthRequestException("Invalid user."); 
    } 

    if (limit == null) { 
     limit = DEFAULT_LIMIT; 
    } 
    query.setRange(0, new Long(limit)); 

    return (List<Score>) pm.newQuery(query).execute(user); 
} 

私は外部からこれをテストしようとしていた理由は、私は、このGoogleのクラウドアプリケーションと統合するために私の既存のモバイルアプリが必要という事実によるものです。好ましくは、Google Cloud Endpointsのクライアント部分を使用せず、Oauth 2.0の手動処理を使用してコードの再構築を最小限に抑えることをお勧めします。

答えて

0

私は、この目的のためにPostmanビルトインのOAuth 2.0認証を使用しませんでしたが、取得したアクセストークンにAuthorizationリクエストヘッダーを設定すると正常に動作するはずです。

キー:

Authorization 

値:

Bearer access_token 
関連する問題