Last active
August 29, 2015 14:20
-
-
Save luisgerhorst/82d28bb7d91b3ee7d86f to your computer and use it in GitHub Desktop.
Generate Rdio access tokens for a user with Erlang oauth lib.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-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