• Post Reply Bookmark Topic Watch Topic
  • New Topic

Google Calendar integration

 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I need to integrate google calendar with my application, but i am getting error like:

com.google.gdata.util.AuthenticationException: Token invalid
<HTML>
<HEAD>
<TITLE>Token invalid</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Token invalid</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

My code are as follows:
One.jps:

<% String requestUrl =
AuthSubUtil.getRequestUrl("http://localhost:8084/GoogleAuthSub/two.jsp",
"https://www.google.com/calendar/feeds/",
false,
true);

String suggestAuthorization = "<p>MyApp needs access to your"+
"Google Calendar account to read your Calendar feed. To authorize"+
"MyApp to access your account, <a href=\"" + requestUrl + "\">log in to your account</a>.</p>";
%>
<%= suggestAuthorization %>
-------------------------------------------------------------------------------------------
two.jsp


<% String myToken = AuthSubUtil.getTokenFromReply(request.getQueryString()); %>

-------------------------------------------------------------------------------------------------------------
And i am using this token in main.java to retrieve all calendar infomations:

main.java

public static void main(String[] args) {
try {
CalendarService myService = new CalendarService("cloudlabz-CPC");
String token = myToken;

//myService.setUserToken(token);
myService.setAuthSubToken(token);

URL feedUrl = new URL("https://www.google.com/calendar/feeds/default/private/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) {
System.out.println("error is: " + e);

}

}


and i am having one exception i.e. com.google.gdata.util.AuthenticationException: Token invalid. I didnt understand what i am missing.

any help would be appreciated.
 
Stefan Evans
Bartender
Posts: 1822
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds pretty straightforward to me.

The token you are sending to authenticate with Google is invalid.

Where does that token come from? How are you getting it into your main program?
Why do you think putting that token into a completely separate random program will authenticate the application for you?

 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am saving the token into my database and use that token for further use so that user don't need to be authenticated every time.

Because I don't want the user to input email id and password, so I don't want the code like

I didnt understand what I am missing, what could I do to solve this?
 
debraj mallick
Ranch Hand
Posts: 188
Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have solved the problem. Anyway thanks.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!