Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
google prediction api example
client_id <- "client id here"
client_secret <- "client secret here"
redirect_uri <- "https://localhost/oauth2callback"
auth_url <- ""
scope <- ""
api_key <- "api key here"
code_url <- paste0(auth_url, "?client_id=", client_id, "&redirect_uri=",
redirect_uri, "&response_type=code&scope=", scope)
# this should open a browser and ask you to login to google. Then it will
# redirect you to a "localhost" page, which doesn't exist,
# copy that code in the url...
# cust and paste that code here...
code <- "paste your code from the last step here"
# use code to get token_code
token.curl.request <- paste0('curl -k --header "Content-Type: application/x-www-form-urlencoded" --data "code=',
code, '&client_id=', client_id, '&client_secret=',
client_secret, '&redirect_uri=', redirect_uri,
token <- system(token.curl.request, intern=T)
token_code <- fromJSON(paste(token, collapse=""))$access_token
# use token_code
hosted.model <- "sample.languageid"
model.url <- ""
model.curl.request <- paste0('curl -k --header "Content-Type: application/json" --data \'{"input":{"csvInstance":["Como se llama?"]}}\' -H "Authorization: Bearer ', token_code, '"', api_key, " --verbose")
system(model.curl.request, intern=T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.