Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tim Fletcher
committed
Sep 26, 2009
1 parent
574b60d
commit 69ae5de
Showing
1 changed file
with
46 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,46 @@ | |||
%% | |||
%% This is an example client for the Twitter API. | |||
%% | |||
%% Example usage: | |||
%% | |||
%% $ make | |||
%% ... | |||
%% $ erl -pa ebin -pa path/to/erlang-oauth/ebin -s crypto -s inets | |||
%% ... | |||
%% 1> Consumer = {"...KEY...", "...SECRET...", hmac_sha1}. | |||
%% ... | |||
%% 2> {ok, Client} = oauth_twitter:start(Consumer). | |||
%% ... | |||
%% 3> {ok, Token} = oauth_twitter:get_request_token(Client). | |||
%% ... | |||
%% 4> AuthorizeURL = oauth_twitter:authorize_url(Token). | |||
%% ... | |||
%% 5> ok = oauth_twitter:get_access_token(Client, "...VERIFIER (PIN)..."). | |||
%% ... | |||
%% 6> {ok, Headers, XML} = oauth_twitter:get_direct_messages(Client). | |||
%% ... | |||
%% | |||
%% Note that before fetching the access token (step 5) you need to have | |||
%% authorized the request token and been given the a verifier PIN at twitter. | |||
%% | |||
-module(oauth_twitter). | |||
|
|||
-compile(export_all). | |||
|
|||
start(Consumer) -> | |||
oauth_client:start(Consumer). | |||
|
|||
get_request_token(Client) -> | |||
URL = "http://twitter.com/oauth/request_token", | |||
oauth_client:get_request_token(Client, URL). | |||
|
|||
authorize_url(Token) -> | |||
oauth:uri("http://twitter.com/oauth/authorize", [{"oauth_token", Token}]). | |||
|
|||
get_access_token(Client, Verifier) -> | |||
URL = "http://twitter.com/oauth/access_token", | |||
oauth_client:get_access_token(Client, URL, [{"oauth_verifier", Verifier}]). | |||
|
|||
get_direct_messages(Client) -> | |||
URL = "http://twitter.com/direct_messages.xml", | |||
oauth_client:get(Client, URL, []). |