user572575
user572575

Reputation: 1049

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("[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());
    }

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().

Upvotes: 1

Views: 5392

Answers (2)

samir
samir

Reputation: 339

i think i got the mistake u r 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.

Upvotes: 0

thinkvantage
thinkvantage

Reputation: 21

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("[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();
            }
    }
}

Upvotes: 1

Related Questions