简体   繁体   中英

How to use Google calendar from a Java Application?

I want to sent SMS from Google calendar with a Java application. I create a Java Desktop Application and add libraries gdata-calendar-2.0.jar , gdata-client-1.0.jar into Libraries.

After that, I create button and paste this code in jButton1ActionPerformed :

CalendarService myService = new CalendarService("exampleCo-exampleApp-1.0");
    myService.setUserCredentials("root@gmail.com", "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());
    }

I have these imports:

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

but it shows cannot find symbol at setUserCredentials, getEntries(), getTitle() .

Maybe your jar files are not set properly on the classpath?

I've tried your code above and it's working properly giving me the correct calendar names.

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("myaccount@gmail.com", "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();
            }
    }
}

i think i got the mistake ur making. please put download gdata-src.java-1.47.1.jar and in that you will find a gdata-core1.0.jar. Just put that in your lib folder by right clicking on the libraries and adding this jar from its location.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM