r-lib / gargle

Infrastructure for calling Google APIs from R, including auth
https://gargle.r-lib.org/
Other
113 stars 33 forks source link

How to use user_params in token_fetch() function #273

Open selesnow opened 1 year ago

selesnow commented 1 year ago

Hello, previosly i use next code:

library(gargle)
library(httr)

# OAuth клиент
app <- oauth_app(
  appname = 'myapp',
  key = 'xxxxxxxxxxxxxxxxxxx.apps.googleusercontent.com',
  secret = 'xxxxxxxxxxxxxxxxxxxxxxxx'
)

# Авторизация
cred <- token_fetch(
  scopes  = 'https://www.googleapis.com/auth/adwords',
  app     = app,
  email   = 'x@gmail.com',
  cache   = TRUE,
  user_params = list(developer_token = "xxxxxxxxxxx")
)

# Создаём запрос
req <- request_build(
  method   = "GET",
  path     = 'v9/customers:listAccessibleCustomers',
  token    = cred,
  base_url = "https://googleads.googleapis.com/"
)

# Отправляем запрос
resp <- request_retry(
  req,
  add_headers(
    `developer-token`= cred$params$user_params$developer_token
  )
)

# Парсим ответ
result <- response_process(resp)

And it worked correctly, but now cred$params$user_params$developer_token is empty, can you help me?

How i need to use user_params argument?

jennybc commented 1 year ago

I haven't intentionally changed anything relating to user_params. Can you give me something like: it works with gargle version X but not with version Y?

selesnow commented 1 year ago

Unfortunately I don't remember which version it worked with.

Tell me, could you give an example code using the user_params argument in the token_fetch() function, and how then to access the passed user parameters in the cred object?

Now i try:

cred <- token_fetch(
  scopes  = 'https://www.googleapis.com/auth/adwords',
  app     = app,
  email   = 'x@gmail.com',
  cache   = TRUE,
  user_params = list(developer_token = "xxxxxxxxxxx")
)

cred$params$user_params$developer_token

But is's doesn't works, cred$params$user_params is empty.