Google Tasks service object for a User who is already authenticated with oAuth2 (Grails/Java) -
i trying google tasks service object has authorised credentials in order can pull tasks user has registered , logged-in (oauth2) our web application via google apps marketplace.
unfortunately receiving 401 - authorization - login required. can tell me going wrong?
here code gettasksservice() method:
def httptransport = new nethttptransport() def jsonfactory = new jacksonfactory(); def clientid = google_client_id def clientsecret = google_secret def applicationname = application_name def tokenresponse = (tokenresponse) googleappsnewoauthservice.getgoogleresponse() def credential = new googlecredential.builder() .setjsonfactory(jsonfactory) .settransport(httptransport) .setclientsecrets(clientid, clientsecret) .build() .setfromtokenresponse(tokenresponse) def service = new com.google.api.services.tasks.tasks.builder(httptransport, jsonfactory, credential) .setapplicationname(applicationname) .build() return service
the code googleappsnewoauthservice.getgoogleresponse() method:
public jsonelement getgoogleresponse() { def session = requestcontextholder.currentrequestattributes().getsession() token googleaccesstoken = (token) session[oauthservice.findsessionkeyforaccesstoken('google')] log.info "google access token: ${googleaccesstoken.token}" if(googleaccesstoken == null) { return null } def googleresource = oauthservice.getgoogleresource(googleaccesstoken, "https://www.googleapis.com/oauth2/v1/userinfo" ) def googleresponse = json.parse(googleresource?.getbody()) return googleresponse }
... , resulting googlejsonresponseexception:
{ "code" : 401, "errors" : [ { "domain" : "global", "location" : "authorization", "locationtype" : "header", "message" : "login required", "reason" : "required" } ], "message" : "login required" } @ com.google.api.client.googleapis.json.googlejsonresponseexception.from(googlejsonresponseexception.java:145)
Comments
Post a Comment