Skip to content

Instantly share code, notes, and snippets.

@danielecook
Created April 13, 2016 14:14
Show Gist options
  • Save danielecook/e8a5f7174e64f28fb91e7e4c90aa5b2e to your computer and use it in GitHub Desktop.
Save danielecook/e8a5f7174e64f28fb91e7e4c90aa5b2e to your computer and use it in GitHub Desktop.
Connect to google datastore through R
library(httr)
library(jsonlite)
# 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 = "",
secret = "")
# 3. Get OAuth credentials
google_token <- oauth2.0_token(oauth_endpoints("google"), myapp,
scope = "https://www.googleapis.com/auth/datastore")
# 4. Use API
resp = list(keys = "test")
req <- POST("https://datastore.googleapis.com/v1beta3/projects/<project_id>:lookup",
config(token = google_token),
body = list(keys = list(path = list(kind = "test", name = "test1"))),
encode = "json",
verbose())
stop_for_status(req)
content(req)
fromJSON(text_content(req))$found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment