2011-11-02 23 views
0

嗨我正在编写一个使用GAE Java的连接器工具,它添加,更新,删除和检索日历events.I使用2腿认证相同。我能够使用双方认证成功添加新事件,但无法使用相同的更新,删除或检索事件。使用GAE Java API无法更新/删除/检索日历事件使用双腿认证使用GAE Java API

当我尝试对日历事件进行更新/删除/检索操作时,它会给出以下错误。

com.google.gdata.util.AuthenticationException:OK

<HTML> 
<HEAD> 
<TITLE>Token invalid - Invalid AuthSub token.</TITLE> 
</HEAD> 
<BODY BGCOLOR="#FFFFFF" TEXT="#000000"> 
<H1>Token invalid - Invalid AuthSub token.</H1> 
<H2>Error 401</H2> 
</BODY> 
</HTML> 

相同的代码工作正常,如果我删除OAuth的特定代码,只需使用service.setUserCredentials()方法。

请帮我解决这个问题。请在 的情况下恢复原状,需要更多相关信息。

在此先感谢。

-Nirzari 下面是代码片段

//Code for getCalendarEvents 
String url = FEED_URL + "?xoauth_requestor_id=" 
             + "[email protected]"; 
URL postUrl = new URL(url); 
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters(); 
       oauthParameters.setScope(Scope); 
       oauthParameters.setOAuthConsumerKey(ConsumerKey); 
       oauthParameters.setOAuthConsumerSecret(secret); 

CalendarService myService = new CalendarService("getAppointments"); 
OAuthSigner signer = new OAuthHmacSha1Signer(); 
myService.setOAuthCredentials(oauthParameters, signer); 
CalendarQuery myQuery = new CalendarQuery(postUrl); 
CustomParameter customParameter = new CustomParameter("showdeleted", 
"true"); 
myQuery.addCustomParameter(customParameter); 
CalendarEventFeed resultFeed = myService.query(myQuery, 
             CalendarEventFeed.class); 

//Code for Update Appointment 
String url = FEED_URL + "?xoauth_requestor_id="          + 
"[email protected]"; 

URL postUrl = new URL(url); 
GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters(); 
oauthParameters.setScope(Scope); 
oauthParameters.setOAuthConsumerKey(ConsumerKey); 
oauthParameters.setOAuthConsumerSecret(secret); 
CalendarService myService = new CalendarService("updateAppointment"); 
OAuthSigner signer = new OAuthHmacSha1Signer(); 
myService.setOAuthCredentials(oauthParameters, signer); 
CalendarQuery myQuery = new CalendarQuery(postUrl); 
myQuery.setExtendedPropertyQuery(new ExtendedPropertyMatch(
             "Prop_Name", value)); 
CalendarEventFeed resultFeed = myService.getFeed(myQuery, 
             CalendarEventFeed.class); 

if (resultFeed != null && resultFeed.getEntries().size() > 0) { 
CalendarEventEntry matchEntry = (CalendarEventEntry) resultFeed 
               .getEntries().get(0); 
updateCalendarEntry(matchEntry, description, title, start, end,    startTime, endTime, location, priavte, guestList); 
matchEntry.update(); 

回答

0

其中一个可能的原因可能是用户的电子邮件没有URL编码(@应编码为%40)。使用此代码可自动处理URL编码:

query.addCustomParameter(new CustomParameter("xoauth_requestor_id", userEmail)); 

而不是手动追加参数。

另一个可能的原因是您的应用没有授权用户所属的Google Apps域的管理员访问日历。您可以在此页面查看:https://www.google.com/a/cpanel/DOMAIN-NAME/ManageOauthClients

+0

非常感谢您的回复,添加了query.addCustomParameter(新的CustomParameter(“xoauth_requestor_id”,userEmail));只是为我工作。 – user1024966

+0

我很乐意提供帮助。可惜你不能投票作为新手:) – lukelazarovic

相关问题