Skip to content
Browse files

Add oauth_twitter module.

  • Loading branch information...
1 parent 574b60d commit 69ae5de9300037525b1e4efca09f1fdc7e957bab @tim tim committed Sep 26, 2009
Showing with 46 additions and 0 deletions.
  1. +46 −0 src/oauth_twitter.erl
View
46 src/oauth_twitter.erl
@@ -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, []).

0 comments on commit 69ae5de

Please sign in to comment.
Something went wrong with that request. Please try again.