Google Task API未列出我的所有任务列表

时间:2012-09-17 05:50:07

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

我尝试使用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为空。但没用。

我做错了什么?

1 个答案:

答案 0 :(得分:0)

那是我的坏事!

我使用GETRequest方法代替POSTReques方法。

更改了以下行:

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

HttpRequest request = rf.buildGetRequest(endPoint);

它的工作正常!