使用gdata-android-2.2.1-alpha检索Google日历列表

时间:2011-08-23 17:07:08

标签: java android android-sdk-2.1

我需要一个简单的工作示例,包含所有相关的导入。 我发现只有一个example,但它过于复杂,缺少许多导入

1 个答案:

答案 0 :(得分:1)

好的,我找到了一个更好的解决方案,我用HttpGet

写了这个
    /***************************************************************************************************************************/
/*                        RETURNS Calendar List                                                                            */
/***************************************************************************************************************************/
//@param authKey, represents the token key ,Auth=......
public void calendarList(String authKey){ 

    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet("https://www.google.com/calendar/feeds/default/allcalendars/full");
    httpget.setHeader("Authorization","GoogleLogin "+authKey);


    // Execute HTTP Post Request
    org.apache.http.HttpResponse response; 
    try {
        response = httpclient.execute(httpget);
        HttpEntity httpEntity = response.getEntity();

        InputStream stream = httpEntity.getContent();
        BufferedReader reader = new BufferedReader(new InputStreamReader(stream));

        StringBuilder total = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            total.append(line);
            Log.d("RESPONSE LIST",line+"\n");                               
        }



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

}