How to integrate with google Calendar? - java

I am new to java. I need to integrate with google calendar form my java allpication.But it gives the Exception message : Error connecting with login URI.I use the following code for connect with google.
CalendarService myService = new CalendarService("CalendarService");
myService.setUserCredentials("calendar.test#gmail.com", "Kdfdfderekra");
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:");
for (int i = 0; i < resultFeed.getEntries().size(); i++) {
CalendarEntry entry = resultFeed.getEntries().get(i);
System.out.println("\t" + entry.getTitle().getPlainText());
}

Use new URL("https://...") instead of new URL ("http://...") as shown in the examples in the Google API documentation.

Related

How to get User's Tumblr Dashboard using Tumblr API?

I am using Jumblr(Tumblr API for Java) in my app to get all the dashboard posts from Tumblr. But I get only 20 posts in return. I want to increase the limit. I have looked into the Jumblr documentation
Kindly help me with this.
My code is below:
JumblrClient client = new JumblrClient(consumer_key, consumer_secret);
client.setToken(OAuthToken, OAuthSecretToken);
// Write the user's name
List<Post> posts = client.userDashboard();
System.out.print("\t"+posts.toString());
for (int i = 0; i<posts.size();i++) {
System.out.println("\t" + posts.get(i).getBlogName());
System.out.println("\t" + posts.get(i).getType());
System.out.println("\t" + posts.get(i).getPostUrl());
}
I found the solution to my problem in the Jumblr docs. I have to pass the options parameter to userDashboard().
Map<String, Integer> options = new HashMap<String, Integer>();
options.put("limit", 50);
List<Post> posts = client.userDashboard(options);

how to get the full tweet of the user timeline with twitter4j?

I want to get tweets from certain user timelines using java library twitter4j, currently I have source code which can get ~ 3200 tweets from user time line but I can't get full tweet. I have searched in various sources on the internet but I can't find a solution to my problem. anyone can help me or can anyone provide an alternative to get a full tweet from the user timeline with java programming?
my source code :
public static void main(String[] args) throws SQLException {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("aaa")
.setOAuthConsumerSecret("aaa")
.setOAuthAccessToken("aaa")
.setOAuthAccessTokenSecret("aaa");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
int pageno = 1;
String user = "indtravel";
List statuses = new ArrayList();
while (true) {
try {
int size = statuses.size();
Paging page = new Paging(pageno++, 100);
statuses.addAll(twitter.getUserTimeline(user, page));
System.out.println("***********************************************");
System.out.println("Gathered " + twitter.getUserTimeline(user, page).size() + " tweets");
//get status dan user
for (Status status: twitter.getUserTimeline(user, page)) {
//System.out.println("*********Place Tweets :**************\npalce country :"+status.getPlace().getCountry()+"\nplace full name :"+status.getPlace().getFullName()+"\nplace name :"+status.getPlace().getName()+"\nplace id :"+status.getPlace().getId()+"\nplace tipe :"+status.getPlace().getPlaceType()+"\nplace addres :"+status.getPlace().getStreetAddress());
System.out.println("["+(no++)+".] "+"Status id : "+status.getId());
System.out.println("id user : "+status.getUser().getId());
System.out.println("Length status : "+status.getText().length());
System.out.println("#" + status.getUser().getScreenName() +" . "+status.getCreatedAt()+ " : "+status.getUser().getName()+"--------"+status.getText());
System.out.println("url :"+status.getUser().getURL());
System.out.println("Lang :"+status.getLang());
}
if (statuses.size() == size)
break;
}catch(TwitterException e) {
e.printStackTrace();
}
}
System.out.println("Total: "+statuses.size());
}
Update :
After the answer given by #AndyPiper
the my problem is every tweet that I get will be truncated or not complete. a tweets that I get will be truncated if the length of tweet more than 140 characters. I found the reference tweet_mode=extended, but I do not know how to use it. if you know something please tell me.
Your Configuration should be like this:
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("aaa")
.setOAuthConsumerSecret("aaa")
.setOAuthAccessToken("aaa")
.setOAuthAccessTokenSecret("aaa")
.setTweetModeExtended(true);
It is explained well here
The Twitter API limits the timeline history to 3200 Tweets. To get more than that you would need to use the (commercial) premium or enterprise APIs to search for Tweets by a specific user.
if you are streaming tweets
fist: you have to add .setTweetModeExtended(true); into your configurationbuilder
second(here is the code)
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
StatusListener listener = new StatusListener(){
public void onStatus(Status status) {
System.out.println("-------------------------------");
if(status.isRetweet()){
System.out.println(status.getRetweetedStatus().getText());
}
else{
System.out.println(status.getText());
}`
its totally works for me.
take care yourself :)
If you are implementing twitter api using twitter4j.properties file and getting truncated timeline text value,simply add the below property in it at the end.
tweetModeExtended=TRUE

How to post in a group on facebook using restfb?

I am trying to post a message onto a facebook group (I am the admin for the page). Here is the java code that I am using:
public void makeTestPost() {
fbClient = new DefaultFacebookClient(groupPageAccessToken);
counter = 0;
fbClient.publish(groupID + "/posts", FacebookType.class, Parameter.with("message", Integer.toString(counter) + ": Hello, fb World!"));
counter++;
}
with:
private final string groupPageAccessToken = "XXXXXXXXXXXXXXXXXX";
private final String groupID = "XXXXXXX";
I got these values using the facebook graph explorer api online Graph API Explorer
But when I login to facebook I don't see any message/post on the group. Please tell me how to make it work?
You need an user access token with the permissions publish_actions and user_managed_groups.
Then you can publish a new message like this:
GraphResponse response = fbClient.publish(groupID + "/feed", GraphResponse.class, Parameter.with("message", Integer.toString(counter) + ": Hello, fb World!"));

Extracting events from Google Calendar

Today I created code:
// Create a CalenderService and authenticate
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("j...#gmail.com", "mypassword");
// Send the request and print the response
URL feedUrl = new URL("https://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());
}
This code gives out the list of all calendars. At me - a box calendar, a calendar of birthdays of friends and a calendar of holidays. I need to receive all events occurring today - i.e. both my notes, and birthdays of friends, and holidays. How I am able to do it?
This code returns event for specified data range, but it is work for private calendar only; i tried to replace "private" for "allcalendars", but it doesn't work:
URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/private/full");
CalendarQuery myQuery = new CalendarQuery(feedUrl);
myQuery.setMinimumStartTime(DateTime.parseDateTime("2006-03-16T00:00:00"));
myQuery.setMaximumStartTime(DateTime.parseDateTime("2006-03-24T23:59:59"));
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("jo#gmail.com", "mypassword");
// Send the request and receive the response:
CalendarEventFeed resultFeed = myService.query(myQuery, Feed.class);
Your problem is in the your feed url. The one you are using is getting the events on the default calendar.
To get the other calendars you should replace default in the url by the calendar's id, for example:
feedUrl = new URL("https://www.google.com/calendar/feeds/xxxxxxxxxxxxxxxxx#group.calendar.google.com/private/full");

Google Calendar API

I have the code:
// Create a CalenderService and authenticate
CalendarService myService = new CalendarService("exampleCo-exampleApp-1");
myService.setUserCredentials("j...#gmail.com", "mypassword");
// Send the request and print the response
URL feedUrl = new URL("https://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());
}
This code gives out the list of all calendars. At me - a box calendar, a calendar of birthdays of friends and a calendar of holidays. I need to receive all events occurring today - i.e. both my notes, and birthdays of friends, and holidays. How I am able to do it?
You need to execute a date range query starting and ending of that day. See
http://code.google.com/apis/calendar/data/2.0/developers_guide_java.html#RetrievingDateRange
(I'm not 100% sure , but I think with the url https://www.google.com/calendar/feeds/default/allcalendars/full you should get results for all your calendars)

Categories