Skip to content

Instantly share code, notes, and snippets.

@luisgerhorst
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save luisgerhorst/82d28bb7d91b3ee7d86f to your computer and use it in GitHub Desktop.
Save luisgerhorst/82d28bb7d91b3ee7d86f to your computer and use it in GitHub Desktop.
Generate Rdio access tokens for a user with Erlang oauth lib.
-define(CONSUMER, {"APPLICATION_KEY", "APPLICATION_SHARED_SECRET", hmac_sha1}).
-define(REQUEST_TOKEN_URL, "http://api.rdio.com/oauth/request_token").
-define(ACCESS_TOKEN_URL, "http://api.rdio.com/oauth/access_token").
access_tokens() ->
application:start(crypto),
application:start(inets),
{ok, RequestTokenResponse} = oauth:post(?REQUEST_TOKEN_URL, [{"oauth_callback", "oob"}], ?CONSUMER),
RequestTokenParams = oauth:params_decode(RequestTokenResponse),
RequestToken = oauth:token(RequestTokenParams),
RequestTokenSecret = oauth:token_secret(RequestTokenParams),
LoginURL = proplists:get_value("login_url", RequestTokenParams),
io:format("Open ~p and enter the shown code here: ", [oauth:uri(LoginURL, [{"oauth_token", RequestToken}])]),
{ok, [Verifier]} = io:fread("", "~d"),
{ok, AccessTokenResponse} = oauth:post(?ACCESS_TOKEN_URL, [{"oauth_verifier", Verifier}], ?CONSUMER, RequestToken, RequestTokenSecret),
AccessTokenParams = oauth:params_decode(AccessTokenResponse),
AccessToken = oauth:token(AccessTokenParams),
AccessTokenSecret = oauth:token_secret(AccessTokenParams),
{AccessToken, AccessTokenSecret}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment