11<?php
2+
23/*
34 * Abraham Williams (abraham@abrah.am) http://abrah.am
45 *
5- * Basic lib to work with Twitter's OAuth beta. This is untested and should not
6- * be used in production code. Twitter's beta could change at anytime.
7- *
8- * Code based on:
9- * Fire Eagle code - http://github.com/myelin/fireeagle-php-lib
10- * twitterlibphp - http://github.com/jdp/twitterlibphp
6+ * The first PHP Library to support OAuth for Twitter's REST API.
117 */
128
139/* Load OAuth lib. You can find it at http://oauth.net */
@@ -46,10 +42,10 @@ class TwitterOAuth {
4642 /**
4743 * Set API URLS
4844 */
49- function accessTokenURL () { return 'https://twitter.com/oauth/access_token ' ; }
45+ function accessTokenURL () { return 'https://api. twitter.com/oauth/access_token ' ; }
5046 function authenticateURL () { return 'https://twitter.com/oauth/authenticate ' ; }
5147 function authorizeURL () { return 'https://twitter.com/oauth/authorize ' ; }
52- function requestTokenURL () { return 'https://twitter.com/oauth/request_token ' ; }
48+ function requestTokenURL () { return 'https://api. twitter.com/oauth/request_token ' ; }
5349
5450 /**
5551 * Debug helpers
@@ -104,11 +100,13 @@ function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
104100 }
105101
106102 /**
107- * Exchange the request token and secret for an access token and
103+ * Exchange request token and secret for an access token and
108104 * secret, to sign API calls.
109105 *
110- * @returns array("oauth_token" => the access token,
111- * "oauth_token_secret" => the access secret)
106+ * @returns array("oauth_token" => "the-access-token",
107+ * "oauth_token_secret" => "the-access-secret",
108+ * "user_id" => "9436992",
109+ * "screen_name" => "abraham")
112110 */
113111 function getAccessToken ($ oauth_verifier = FALSE ) {
114112 $ parameters = array ();
@@ -122,7 +120,27 @@ function getAccessToken($oauth_verifier = FALSE) {
122120 }
123121
124122 /**
125- * GET wrappwer for oAuthRequest.
123+ * One time exchange of username and password for access token and secret.
124+ *
125+ * @returns array("oauth_token" => "the-access-token",
126+ * "oauth_token_secret" => "the-access-secret",
127+ * "user_id" => "9436992",
128+ * "screen_name" => "abraham",
129+ * "x_auth_expires" => "0")
130+ */
131+ function getXAuthToken ($ username , $ password ) {
132+ $ parameters = array ();
133+ $ parameters ['x_auth_username ' ] = $ username ;
134+ $ parameters ['x_auth_password ' ] = $ password ;
135+ $ parameters ['x_auth_mode ' ] = 'client_auth ' ;
136+ $ request = $ this ->oAuthRequest ($ this ->accessTokenURL (), 'POST ' , $ parameters );
137+ $ token = OAuthUtil::parse_parameters ($ request );
138+ $ this ->token = new OAuthConsumer ($ token ['oauth_token ' ], $ token ['oauth_token_secret ' ]);
139+ return $ token ;
140+ }
141+
142+ /**
143+ * GET wrapper for oAuthRequest.
126144 */
127145 function get ($ url , $ parameters = array ()) {
128146 $ response = $ this ->oAuthRequest ($ url , 'GET ' , $ parameters );
@@ -133,7 +151,7 @@ function get($url, $parameters = array()) {
133151 }
134152
135153 /**
136- * POST wreapper for oAuthRequest.
154+ * POST wrapper for oAuthRequest.
137155 */
138156 function post ($ url , $ parameters = array ()) {
139157 $ response = $ this ->oAuthRequest ($ url , 'POST ' , $ parameters );
@@ -144,7 +162,7 @@ function post($url, $parameters = array()) {
144162 }
145163
146164 /**
147- * DELTE wrapper for oAuthReqeust.
165+ * DELETE wrapper for oAuthReqeust.
148166 */
149167 function delete ($ url , $ parameters = array ()) {
150168 $ response = $ this ->oAuthRequest ($ url , 'DELETE ' , $ parameters );
0 commit comments