vb.net - Authenticating Google Contacts v3 (can't I use my Google Calendar token)? -
i have seen few topics on issue maybe overlooking something.
this current vb code authticate calendar:
private function doauthentication(byref rstrtoken string) boolean dim credential usercredential dim secrets = new clientsecrets() secrets.clientid = m_strclientid secrets.clientsecret = m_strclientsecret m_scopes.add(calendarservice.scope.calendar) try credential = googlewebauthorizationbroker.authorizeasync(secrets, m_scopes, "user", cancellationtoken.none, new filedatastore("xxxxx.calendar.application")).result() ' create calendar service using initializer instance dim initializer new baseclientservice.initializer() initializer.httpclientinitializer = credential initializer.applicationname = "public talks , meeting schedule assistant calendar" m_service = new calendarservice(initializer) rstrtoken = credential.token.accesstoken.tostring() catch ex exception ' encountered kind of problem, perhaps have not yet authenticated? ' can isolate exception? return false end try return true end function
i want work google contact data. modified above method include scope:
m_scopes.add("https://www.google.com/m8/feeds/")
then tried use it:
if (doauthentication(strtoken)) dim settings new requestsettings("xx", strtoken) settings.autopaging = true iresult = result_success_oauth m_contactsrequest = new contactsrequest(settings) dim f feed(of contact) = m_contactsrequest.getcontacts() each ocontact contact in f.entries console.writeline(ocontact.name.tostring) next else return result_failed_oauth end if
but raises exception: 401 unauthorized.
what doing wrong? thank you.
update
i found webpage: http://www.daimto.com/google-contacts-with-c/
so tried implement of it:
private function doauthentication(byref rstrtoken string, byref rparameters oauth2parameters) boolean dim credential usercredential dim secrets = new clientsecrets() secrets.clientid = m_strclientid secrets.clientsecret = m_strclientsecret m_scopes.add(calendarservice.scope.calendar) m_scopes.add("https://www.google.com/m8/feeds/")
try credential = googlewebauthorizationbroker.authorizeasync(secrets, m_scopes, "user", cancellationtoken.none, new filedatastore("xx.calendar.application")).result() ' create calendar service using initializer instance dim initializer new baseclientservice.initializer() initializer.httpclientinitializer = credential initializer.applicationname = "public talks , meeting schedule assistant calendar" m_service = new calendarservice(initializer) rstrtoken = credential.token.accesstoken.tostring() rparameters.accesstoken = credential.token.accesstoken rparameters.refreshtoken = credential.token.refreshtoken catch ex exception ' encountered kind of problem, perhaps have not yet authenticated? ' can isolate exception? return false end try
and code:
dim parameters new oauth2parameters if (doauthentication(strtoken, parameters)) dim settings new requestsettings("googlecalif", parameters) settings.autopaging = true iresult = result_success_oauth m_contactsrequest = new contactsrequest(settings) dim f feed(of contact) = m_contactsrequest.getcontacts() each ocontact contact in f.entries console.writeline(ocontact.name.tostring) next else return result_failed_oauth end if return true end function
but still 401 exception. have correctly added contacts api google console. confused.
i afraid have headache. can't past 401 unathorized issue.
i got working! there few things had do.
step 1
it seems needed scopes 1 line string space in between. changed authentication method to:
private function doauthentication(byref rstrtoken string, byref rparameters oauth2parameters) boolean dim credential usercredential dim secrets = new clientsecrets() secrets.clientid = m_strclientid secrets.clientsecret = m_strclientsecret m_scopes.add("https://www.googleapis.com/auth/calendar https://www.google.com/m8/feeds/") try credential = googlewebauthorizationbroker.authorizeasync(secrets, m_scopes, "user", cancellationtoken.none, new filedatastore("publictalksoftware.calendar.application")).result() ' create calendar service using initializer instance dim initializer new baseclientservice.initializer() initializer.httpclientinitializer = credential initializer.applicationname = "public talks , meeting schedule assistant calendar" m_service = new calendarservice(initializer) rstrtoken = credential.token.accesstoken.tostring() rparameters.accesstoken = credential.token.accesstoken rparameters.refreshtoken = credential.token.refreshtoken catch ex exception ' encountered kind of problem, perhaps have not yet authenticated? ' can isolate exception? return false end try return true end function
i commented out line calendarservice.scope.calendar , used literal text. not sure if best thing do.
step 2
in aforementioned method passed in oauth2parameters object , populated couple of entries.
step 3
the calling code this:
dim m_contactsrequest contactsrequest dim strtoken string = "" dim iresult integer = 0 dim parameters new oauth2parameters if (doauthentication(strtoken, parameters)) iresult = result_success_oauth else return result_failed_oauth end if try dim settings new requestsettings("xx", parameters) m_contactsrequest = new contactsrequest(settings) dim f feed(of contact) = m_contactsrequest.getcontacts() each ocontact contact in f.entries console.writeline(ocontact.name.fullname.tostring) next catch ex exception ' encountered kind of problem, perhaps have not yet authenticated? ' can isolate exception? return false end try
step 4
since had access token on pc, had revoke it, access contacts opposed calendar service.
Comments
Post a Comment