2011-10-06 58 views
1

我想通過Java應用程序從Google日曆發送短信。我創建了一個Java桌面應用程序,並將庫文件gdata-calendar-2.0.jar,gdata-client-1.0.jar添加到庫中。如何從Java應用程序使用Google日曆?

在那之後,我創建按鈕並粘貼此代碼在jButton1ActionPerformed

CalendarService myService = new CalendarService("exampleCo-exampleApp-1.0"); 
    myService.setUserCredentials("[email protected]", "pa$$word"); 

    URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/allcalendars/full"); 
    CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class); 

    System.out.println("Your calendars:"); 
    System.out.println(); 

    for (int i = 0; i < resultFeed.getEntries().size(); i++) { 
     CalendarEntry entry = resultFeed.getEntries().get(i); 
     System.out.println("\t" + entry.getTitle().getPlainText()); 
    } 

我有這些進口:

import com.google.gdata.client.calendar.*; 
import com.google.gdata.data.calendar.*; 

,但它顯示在setUserCredentials無法找到符號,getEntries() getTitle()

回答

1

也許你的jar文件沒有在類路徑上正確設置?

我試過你的代碼,它正常工作給我正確的日曆名稱。

import java.net.URL; 
import com.google.gdata.client.calendar.*; 
import com.google.gdata.data.calendar.*; 

public class GoogleTest { 

    public static void main(String[] args){ 
      try{ 
       CalendarService myService = new CalendarService("exampleCo-exampleApp-1.0"); 
       myService.setUserCredentials("[email protected]", "mypass"); 
       URL feedUrl = new URL("http://www.google.com/calendar/feeds/default/allcalendars/full"); 
       CalendarFeed resultFeed = myService.getFeed(feedUrl, CalendarFeed.class); 
       System.out.println("Your calendars:"); 
       System.out.println(); 
       for (int i = 0; i < resultFeed.getEntries().size(); i++) { 
        CalendarEntry entry = resultFeed.getEntries().get(i); 
        System.out.println("\t" + entry.getTitle().getPlainText()); 
       } 
      }catch(Exception e){ 
       e.printStackTrace(); 
      } 
    } 
} 
0

我想我犯了錯​​誤。請把下載的gdata-src.java-1.47.1.jar放到這裏,你會發現一個gdata-core1.0.jar。只需將它放在lib文件夾中,右鍵單擊庫並從其位置添加此jar。

相關問題