測試Java服務器上的谷歌雲端點我部署此回購到谷歌應用程序引擎是谷歌雲端點Java服務器的一個例子。 https://github.com/GoogleCloudPlatform/appengine-endpoints-tictactoe-java無法從郵差
的應用程序正常工作。我能夠使用Google API Explorer測試REST API調用。不過,我想考這些REST API調用來使用外部工具如郵差(Chrome擴展程序,這是一個REST客戶端)這個程序等
我已經成功地檢索從谷歌的訪問令牌。但是當我從Postman或普通瀏覽器撥打電話時,應用程序一直拒絕使用「無效用戶」錯誤的API調用。我試着記錄輸入的用戶返回null。
以下代碼段是我試圖達到的REST API。作爲該方法參數的用戶從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 Cloud Endpoints的客戶端部分,而是使用Oauth 2.0的手動處理來儘量減少代碼重構。