java - Google Calendar API and OAuth problem -
i error
com.google.gdata.util.authenticationexception: unknown authorization header @ com.google.gdata.client.http.httpgdatarequest.handleerrorresponse(httpgdatarequest.java:600) ~[gdata-core-1.0.jar:na] @ com.google.gdata.client.http.googlegdatarequest.handleerrorresponse(googlegdatarequest.java:563) ~[gdata-core-1.0.jar:na] @ com.google.gdata.client.http.httpgdatarequest.checkresponse(httpgdatarequest.java:552) ~[gdata-core-1.0.jar:na] @ com.google.gdata.client.http.httpgdatarequest.execute(httpgdatarequest.java:530) ~[gdata-core-1.0.jar:na] @ com.google.gdata.client.http.googlegdatarequest.execute(googlegdatarequest.java:535) ~[gdata-core-1.0.jar:na]
when trying access google calendar data via api.
here happens before error.
1) authenticate google:
final accesstokenresponse response = new googleauthorizationcodegrant(httptransport, jsonfactory, clientid, clientsecret, authorizationcode, redirecturl).execute(); final googleaccessprotectedresource accessprotectedresource = new googleaccessprotectedresource( response.accesstoken, httptransport, jsonfactory, clientid, clientsecret, response.refreshtoken); logger.debug("response.accesstoken: {}", response.accesstoken); this.oauthaccesstoken = response.accesstoken; ...
2) read data via tasks api:
this.service = new tasks(httptransport, accessprotectedresource, jsonfactory); this.service.setapplicationname(this.applicationname);
this seems work.
3) try read data google calendar api:
final oauthhmacsha1signer signer = new oauthhmacsha1signer(); final googleoauthparameters oauth = new googleoauthparameters (); oauth.setoauthconsumerkey("myapp.com"); oauth.setoauthconsumersecret(client_secret); // client secret "google api access" page, "client secret" entry oauth.setoauthtoken(this.oauthaccesstoken); // access token step 1 oauth.setoauthtokensecret(aauthorizationcode); // aauthorizationcode taken callback url. // http://myapp.com/oauth2callback?code=4/uy8arb4bhrpwwysr3qwkpt9lizkt // aauthorizationcode equal "4/uy8arb4bhrpwwysr3qwkpt9lizkt" (without quotes) oauth.setscope(scope_calendar); // https://www.google.com/calendar/feeds/ final calendarservice calendarservice = new calendarservice(application_name); calendarservice .setoauthcredentials(oauth, signer); logger.debug("calendarservice: {}", calendarservice); final url feedurl = new url( "http://www.google.com/calendar/feeds/default/allcalendars/full"); final calendarfeed resultfeed = calendarservice.getfeed(feedurl, calendarfeed.class);
at last line (calendarservice.getfeed...) aforementioned exception occurs.
i have following questions:
1) call
oauth.setoauthconsumerkey
correct?
i. e. "consumer key" equal "product name" in google api console, or "client id" field (value 42912397129473.apps.googleusercontent.com)
2) setoauthtokensecret correct? i. e. code get, when google redirects user app?
3) if questions 2 , 3 answered yes, else can cause of problem?
thanks
dmitri
p. s.: previously, access google calendar simple access (i. e. google user name , password). however, not option because users of app not want give away google password.
finally, solved problem following example at
http://code.google.com/p/gdata-java-client/source/browse/trunk/java/sample/oauth/oauthexample.java
my advice future victims^w users of oauth: pay attention smallest details in oauth tutorials. oauth devil lies in details.
Comments
Post a Comment