Skip to content

Instantly share code, notes, and snippets.

@navicore
Last active February 15, 2018 21:48
Show Gist options
  • Save navicore/26a2e1e7428640d35c6d to your computer and use it in GitHub Desktop.
Save navicore/26a2e1e7428640d35c6d to your computer and use it in GitHub Desktop.
oauth2 to coinbase via R
# oauth2 to coinbase via R
# define your oauth2 app to get "Client ID" and "Client Secret" at https://www.coinbase.com/settings/api
appKey="<MY_CLIENT_ID>"
appSecret="<MY_CLIENT_SECRET>"
require(httr)
require(jsonlite)
require(httpuv)
endpoints <- oauth_endpoint(
authorize = "https://www.coinbase.com/oauth/authorize",
access="https://www.coinbase.com/oauth/token")
)
myapp <- oauth_app("coinbase", key=appKey, secret=appSecret)
# see https://developers.coinbase.com/api#permissions-scopes for
# a list of all possible scopes/permissions
ctoken <- oauth2.0_token(endpoints, myapp, cache=FALSE,scope="user")
#--- at this point, you are done authenticating ---
# list accounts by passing the access and refresh tokens along with the request
req <- GET("https://api.coinbase.com/v1/accounts",
config(token = ctoken))
stop_for_status(req)
content(req)
  • the httpuv package seems to have hardcoded the callback uri to http://localhost:1410/, so you'll need to create an OAuth2 Application definition at coinbase that uses that uri.
  • the good news is that it works, you can access coinbase via R without cut-and-paste'ing tokens!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment