2012-08-08 7 views
1

Google 캘린더 API를 사용하고 있습니다. 호기심에서 나는 Google 도서관을 사용하지 않으므로 직접 작성할 수 있습니다. 새 캘린더를 만들 수 없습니다. https://developers.google.com/google-apps/calendar/v3/reference/calendarList/list자바 : Google 캘린더 API

을 내가 사용하는 새 달력 만들기를 들면 다음과 같습니다 :이 얻을 요청이 작동하기 때문에 인증이 작동 https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert

을 내가 쓴 :

try {   
    DefaultHttpClient httpclient = new DefaultHttpClient(); 
    httpclient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,false); 
    HttpPost httppost = new HttpPost("https://www.googleapis.com/calendar/v3/users/me/calendarList"); 
    httppost.addHeader("Authorization", "Bearer " + token); //authentication 
    httppost.addHeader("Host", "googleapis.com"); 

    StringEntity params = new StringEntity("{\"id\": \"TestSchedule\",\"defaultReminders\":[{\"method\": \"popup\",\"minutes\":10}]}"); 
    httppost.setEntity(params); 

    //EXECUTE REQUEST 
    HttpResponse postResponse = httpclient.execute(httppost); 

    //RESPONSE 
    HttpEntity entity = postResponse.getEntity(); 
    InputStream stream = entity.getContent(); 
    BufferedReader br = new BufferedReader(new InputStreamReader(stream,"UTF-8")); 
    String line; 
    while ((line = br.readLine()) != null) { 
     System.out.println(line); 
    } 
    httppost.releaseConnection(); 

} catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

또한 범위를 올바른 토큰을 얻을 수 있습니다 : https://www.googleapis.com/auth/calendar 정확해야합니다. 문제는 내 게시물 요청 본문에 있다고 생각합니까?

따라서 get 요청이 작동하므로 인증 절차가 정확하다고 가정하고 올바른 토큰을 얻습니다. get 요청 결과 대신이 게시물 요청을 수행하면 302 응답 코드가됩니다. 새로운 URL은 Google의 기본 페이지이며 참조 페이지에 따르면 캘린더 리소스를 받아야합니다.

답변

0
The following code working. please u can check it now. 



     { 
     DefaultHttpClient httpclient = new DefaultHttpClient(); 
     httpclient.getParams().setParameter(ClientPNames.HANDLE_REDIRECTS,false); 
     HttpGet httpget = new HttpGet("https://www.googleapis.com/calendar/v3/users/me/calendarList"); 
     httpget.addHeader("Authorization", "Bearer " + accessToken); 

     //HttpPost httppost = new HttpPost("https://www.googleapis.com/calendar/v3/users/me/calendarList"); 
     //httppost.addHeader("Authorization", "Bearer " + accessToken); //authentication 
     // httppost.addHeader("Host", "googleapis.com"); 

     /* StringEntity params = new StringEntity("{\"id\":}"); 
     httppost.setEntity(params);*/ 

     //EXECUTE REQUEST 
     HttpResponse postResponse = httpclient.execute(httpget); 

     //RESPONSE 
     HttpEntity entity = postResponse.getEntity(); 
     String responseBody1 = EntityUtils.toString(entity); 
     logger.debug(responseBody1); 
     }