1

Referencing this post , I tried to create an access token for my Google Actions. I enabled Google sign in, and end up with a user-id. The top post says "You can combine this with a web- or app-based Google Sign-In to get their permission to access OAuth scopes if you need to access Google's APIs" but I honestly have no idea how to do that. What I'm trying to do is get an access token from Google Actions/ Dialog flow to send to my server-end code in order to make a successful API POST request to Google Calendar API.

1 Answers1

0

The post you reference that points to another StackOverflow answer that discusses the approach. It basically says that you need to combine two things to do what you want:

  1. You use Google Sign In on a web page to let the user authorize you to access the calendar on their behalf.
    • You probably should use the hybrid flow so the access/refresh tokens are only handled on the server side - not in your web client.
    • Your server will store the access/refresh tokens in some way so you can use them as part of your Action later.
  2. You will use Google Sign In for Assistant to authenticate the user when they connect through the Assistant and determine if they have already authorized you to access their calendar. If they have, you'll be able to get their access/refresh tokens out of your store and access their calendar.

You can't do it completely through AoG/Dialogflow because there is no way for the user to grant OAuth permissions to you by voice alone - this is why you need to direct the user to a web page for them to grant you permission to access their calendar.

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • one more question: I have successfully linked my google action to the google api service and it gives me a working access token once I use google sign in for my action on a mobile device. My new problem is that I have to repeatedly go through this Google sign-in process every hour or so. Do you know any ways to keep a google sign-in session logged in for a extended period of time? Note that I'm using this access token to make a freebusy request to my a plethora of my google calendars. (I'm using this internally, so I'll never need to publish this action). – Charles Renk Jan 24 '19 at 19:33
  • You would use a refresh token to do this. If you're still confused, it would be best to open a new StackOverflow question, discussing how you're getting the access token now, and the issues you're having. – Prisoner Jan 24 '19 at 19:47