File: oauth2-google.r

package info (click to toggle)
r-cran-httr 1.4.5%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 968 kB
  • sloc: sh: 9; makefile: 2
file content (25 lines) | stat: -rw-r--r-- 675 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
library(httr)

# 1. Find OAuth settings for google:
#    https://developers.google.com/accounts/docs/OAuth2InstalledApp
oauth_endpoints("google")

# 2. Register an application at https://cloud.google.com/console#/project
#    Replace key and secret below.
myapp <- oauth_app("google",
  key = "16795585089.apps.googleusercontent.com",
  secret = "hlJNgK73GjUXILBQvyvOyurl"
)

# 3. Get OAuth credentials
google_token <- oauth2.0_token(oauth_endpoints("google"), myapp,
  scope = "https://www.googleapis.com/auth/userinfo.profile"
)

# 4. Use API
req <- GET(
  "https://www.googleapis.com/oauth2/v1/userinfo",
  config(token = google_token)
)
stop_for_status(req)
content(req)