【问题标题】:Google Task API isn't listing all my tasklistGoogle Task API 没有列出我的所有任务列表
【发布时间】:2012-09-17 05:50:06
【问题描述】:

我尝试使用 OAuth Playground,它运行良好,并返回了我所有的 10 个任务列表。但以下是我返回有线响应的 Java 代码。

HttpTransport httpTransport = new NetHttpTransport();
JacksonFactory jsonFactory = new JacksonFactory();

String clientId = "[MYCLIENTID].apps.googleusercontent.com";
String clientSecret = "[MYCLIENTSECRET]";
String refreshToken = "1/P_mWwxnZEJHlDLiUs_BzMIvx6MDewDmvrgx-LNTfib0";

GoogleRefreshTokenGrant authRequest = new GoogleRefreshTokenGrant(httpTransport, jsonFactory, clientId, clientSecret, refreshToken);        
authRequest.useBasicAuthorization = false;

AccessTokenResponse authResponse = authRequest.execute();
GoogleAccessProtectedResource access = new GoogleAccessProtectedResource(authResponse.accessToken, httpTransport, jsonFactory, clientId, clientSecret, authResponse.refreshToken);

HttpRequestFactory rf = httpTransport.createRequestFactory(access);

String endPointUrl = "https://www.googleapis.com/tasks/v1/users/@me/lists";
GenericUrl endPoint = new GenericUrl(endPointUrl);
String requestBody = "{\"maxResults\":10000}"; 
HttpRequest request = rf.buildPostRequest(endPoint, ByteArrayContent.fromString("application/json", requestBody));
HttpResponse response = request.execute();

String str = response.parseAsString();
utils.log(str);     

以下是我的回复:

{
    "kind": "tasks#taskList",
    "id": "MDA4NTI1NjMwNTAxMTQ5ODQ0NzM6OTA1NjU0MjI6MA",
    "etag": "\"M3V2EYzE8ZKSrA5JDxxyFB0Dbp4/zpmuA0Fyh_wtIkaqHMXDWlYqzd8\"",
    "title": "",
    "updated": "2012-09-17T05:38:05.000Z",
    "selfLink": "https://www.googleapis.com/tasks/v1/users/@me/lists/MDA4NTI1NjMwNTAxMTQ5ODQ0NzM6OTA1NjU0MjI6MA"
}

我什至尝试将requestBody 留空。但是没用。

我做错了什么?

【问题讨论】:

    标签: java google-api google-api-java-client


    【解决方案1】:

    那是我的错!

    我使用POSTRequest 方法代替了GETRequest 方法。

    更改了以下行:

    HttpRequest request = rf.buildPostRequest(endPoint, ByteArrayContent.fromString("application/json", requestBody));
    

    HttpRequest request = rf.buildGetRequest(endPoint);
    

    而且效果很好!

    【讨论】:

      猜你喜欢
      • 2014-02-05
      • 1970-01-01
      • 2020-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多