2012-09-17 46 views
0

我嘗試了OAuth Playground,它運行良好,並返回我所有的10個任務列表。但以下是我的Java代碼,它返回我的有線響應。谷歌任務API沒有列出我所有的任務列表

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空嘗試。但沒用。

我做錯了什麼?

回答

0

這是我的不好!

而不是GETRequest方法,我用POSTReques t方法。

更改以下行:

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

HttpRequest request = rf.buildGetRequest(endPoint); 

及其工作得很好!