1

I'm fairly new to API topic. So far i've managed to obtain access token (but its only valid for short period) and get information how the oauth dance is carried out by httr package but could not figure out what params should i put to obtain refresh token either found info on it. only hint i've is documentation(page24):
https://cran.r-project.org/web/packages/httr/httr.pdf
Subject of interest is yt analytics api.

key <- client_id
secret <- client_secret
myapp <- oauth_app("google", key, secret)
token <- oauth2.0_token(oauth_endpoints("google"),
                        myapp,
                        scope=c("https://www.googleapis.com/auth/youtube.readonly", 
                                "https://www.googleapis.com/auth/yt-analytics.readonly"))

returns valid access token (1h valid time) but the correct thing i want is refresh token.

> token$can_refresh()
[1] FALSE
> token$refresh()
Error: Refresh token not available
rkabuk
  • 267
  • 3
  • 15

1 Answers1

0

setting query_authorize_extra parameter to offline as specified in google api documentation did the job.

some other stack questions on same topic suggested setting type to offline. this does not work and is deprecated

token <- oauth2.0_token(oauth_endpoints("google"),
                        myapp,
                        scope=c("https://www.googleapis.com/auth/youtube.readonly", 
                                "https://www.googleapis.com/auth/yt-analytics.readonly"),
                        query_authorize_extra = list(access_type= "offline"))

returns:

> token$can_refresh()
[1] TRUE
> token$refresh()
<Token>
<oauth_endpoint>
 authorize: https://accounts.google.com/o/oauth2/auth
 access:    https://accounts.google.com/o/oauth2/token
 validate:  https://www.googleapis.com/oauth2/v1/tokeninfo
 revoke:    https://accounts.google.com/o/oauth2/revoke
<oauth_app> google
  key:    ####################################
  secret: <hidden>
<credentials> access_token, expires_in, refresh_token, scope, token_type
---
rkabuk
  • 267
  • 3
  • 15