简体   繁体   English

Grails OAuth插件:无法在Google中创建新的日历事件

[英]Grails oauth plugin: unable to create a new calendar event in google

I am using grails Oauth plugin. 我正在使用grails Oauth插件。 And I am unable to create a new event in google calendar. 我无法在Google日历中创建新活动。

Service code: 服务代码:

def addNewEvent(String calendarId){
    Token token=getGoogleAccessToken()
    def calendars = oauthService.postGoogleResource(token, "https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events?key=${grailsApplication.config.oauth.providers.google.key}", [end:'2013-09-26', start: '2013-09-26', summery: 'Testing'])
} 

Logs: 日志:

signing request: https://www.googleapis.com/calendar/v3/calendars/vrg3e08emcipgm4772u2iep2h4@group.calendar.google.com/events?key=163071926482.apps.googleusercontent.com
setting token to: Token[1/xxx-xxx , xxx_yyy]
generating signature...
base string is: POST&https%3A%2F%2Fwww.googleapis.com%2Fcalendar%2Fv3%2Fcalendars%2Fvrg3e08emcipgm4772u2iep2h4%40group.calendar.google.com%2Fevents&end%3D2013-09-26%26key%3D163df071926482.apps.googleusercontent.com%26oauth_consumer_key%3D1630719264df82.apps.googleusercontent.com%26oauth_nonce%3D254349338721%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1380260738%26oauth_token%3D1%252FSH5y9a8gO4AdG5bG3okN2348bi4tcxYdF-B3TL3jzN1kfw%26oauth_version%3D1.0%26scope%3Dhttps%253A%252F%252Fwww.googleapis.com%252Fauth%252Fcalendar%26start%3D2013-09-26%26title%3DTesting
signature is: ft/wk6omCDRh2Dk5jhC7NpBK1V4=
appended additional OAuth parameters: { oauth_signature -> ft/wk6omCDRh23Dk5jhC7NpBK1V4= , scope -> https://www.googleapis.com/auth/calendar , oauth_version -> 1.0 , oauth_nonce -> 2543498721 , oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> 163071926482.apps.googleusercontent.com , oauth_token -> 1/SH5y9a8gO433AdG5bG3okN8bi4tcxYdF-B3TL3jzN1kfw , oauth_timestamp -> 1380260738 }
using Http Header signature

When I make this call via Google api Explorer , it is working. 当我通过Google api Explorer拨打电话时,它正在工作。

Can anyone please give me some idea how to create a calendar event or where I am wrong? 谁能给我一些想法,如何创建日历活动或我错了?

On a first look, bodyParameters as per the api looks different. bodyParameters ,根据api的 bodyParameters看起来有所不同。 end and start are nested objects. endstart是嵌套对象。

Shouldn't you try with the below bodyParameters : 您不应该尝试使用以下bodyParameters

['end.date':'2013-09-26', 'start.date':'2013-09-26', summary:'Testing']

You can also try 您也可以尝试

[end:[date:'2013-09-26'], start:[date:'2013-09-26'], summary:'Testing']

Also rectify summery with summary . 此外整顿summerysummary

I can look into it in detail if the above is not the reason of discrepancy. 如果上述不是差异的原因,我可以详细研究。

UPDATE UPDATE
I was able to replicate your issue. 我能够复制您的问题。 After digging for a long period of time, found that grails oauth plugin does not support Google Oauth 2 API. 经过长时间的挖掘,发现grails oauth插件不支持 Google Oauth 2 API。 There has been a pull request submitted for the same. 已经提交了相同的请求请求

You can use the changes provided by the pull request or directly use scribe with the latest Google2Api as mentioned in this fork and as an example in detail. 您可以使用pull请求提供的更改,也可以直接使用scribe和最新的Google2Api(本分叉中所述)并作为示例

Definitely, the parameter map was an issue, the above setup for end date, start date and summary has to be used. 毫无疑问,参数映射是个问题,必须使用以上设置的结束日期,开始日期和摘要。 I am looking into it as well to see if I can successfully provide a working example for the same in groovy or as a Grails project in github. 我也在研究它,看看是否可以在groovy或github中的Grails项目中成功提供一个工作示例。 I would also see how the pull request affects the plugin. 我还将看到pull请求如何影响插件。 BTW, I tested with Oauth v2.2.1 plugin. 顺便说一句,我测试了Oauth v2.2.1插件。

Hope that helps, will keep this answer updated as and when I proceed further. 希望能有所帮助,在我进一步进行操作时,将使此答案保持最新。

I tried google API console to create a quick event and it create an event in my calander. 我尝试使用Google API控制台创建一个快速事件,并在我的日历中创建一个事件。 I tried this in sample application. 我在示例应用程序中尝试过此操作。

def google() {
    Token token = (Token) session[oauthService.findSessionKeyForAccessToken('google')]
    def text = "Test Data".encodeAsURL()
    def calendarId = "asd@xyz.com".encodeAsURL()
    def calendars = oauthService.postGoogleResource(token, "https://www.googleapis.com/calendar/v3/calendars/${calendarId}/events/quickAdd?text=${text}&sendNotifications=true&key=${grailsApplication.config.oauth.providers.google.key}")
    def calendarsJSON = JSON.parse(calendars.body)
    render calendarsJSON.toString()
}

Above code successfully create an event with name Test Data for one hour in my google calendar. 上面的代码在我的Google日历中成功创建了一个名为Test Data的事件,持续了一个小时。

I am trying to create an event for specific time. 我正在尝试为特定时间创建活动。 I will update this post after creating event successfully. 成功创建活动后,我将更新此帖子。 And these are my logs. 这些是我的日志。

signing request: https://www.googleapis.com/calendar/v3/calendars/abc%xyz.com/events/quickAdd?text=Test+Data&sendNotifications=true&key=28284284224.apps.googleusercontent.com
setting token to: Token[1/bhhuujnin , d7ispjnkjnkSUsX8ckIdVOIH0bLXQa]
generating signature...
base string is: POST&https%3A%2F%2Fwww.googleapis.com%2Fcalendar%2Fv3%2Fcalendars%2Fabc%2540xyz.com%2Fevents%2FquickAdd&key%3D28284284224.apps.googleusercontent.com%26oauth_consumer_key%3D28284284224.apps.googleusercontent.com%26oauth_nonce%3D28284284224%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1381555963%26oauth_token%3D1%252Fifa0cTEhk6VRmU_YAQ61pX9Nsvdvsdg8BN7fbAyTKmBlBcIZ7A%26oauth_version%3D1.0%26scope%3Dhttps%253A%252F%252Fwww.googleapis.com%252Fauth%252Fcalendar%26sendNotifications%3Dtrue%26text%3DTest%2520Data
signature is: TmuhOi8ockEPKdjhjiK5fPMyVJ2wfU=
appended additional OAuth parameters: { oauth_signature -> TmuhOi8ockEPkhkKdiK5fPMyVJ2wfU= , scope -> https://www.googleapis.com/auth/calendar , oauth_version -> 1.0 , oauth_nonce -> 3332489143 , oauth_signature_method -> HMAC-SHA1 , oauth_consumer_key -> 28284284224.apps.googleusercontent.com , oauth_token -> 1/ifa0cTEhk6VRmU_YAQsfgeg_61pX9N8BN7fbAyTKmBlBcIZ7A , oauth_timestamp -> 1381555963 }
using Http Header signature

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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