Skip to content
This repository
Browse code

Added getXAuthToken method, updated documentation and fixed some spel…

…ling issues.
  • Loading branch information...
commit 76446fa719466c09b20fe021bf9e92f54afc43e1 1 parent 8da02a6
Abraham Williams authored March 10, 2010

Showing 1 changed file with 32 additions and 14 deletions. Show diff stats Hide diff stats

  1. 46  twitteroauth/twitteroauth.php
46  twitteroauth/twitteroauth.php
... ...
@@ -1,13 +1,9 @@
1 1
 <?php
  2
+
2 3
 /*
3 4
  * Abraham Williams (abraham@abrah.am) http://abrah.am
4 5
  *
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.
11 7
  */
12 8
 
13 9
 /* Load OAuth lib. You can find it at http://oauth.net */
@@ -46,10 +42,10 @@ class TwitterOAuth {
46 42
   /**
47 43
    * Set API URLS
48 44
    */
49  
-  function accessTokenURL()  { return 'https://twitter.com/oauth/access_token'; }
  45
+  function accessTokenURL()  { return 'https://api.twitter.com/oauth/access_token'; }
50 46
   function authenticateURL() { return 'https://twitter.com/oauth/authenticate'; }
51 47
   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'; }
53 49
 
54 50
   /**
55 51
    * Debug helpers
@@ -104,11 +100,13 @@ function getAuthorizeURL($token, $sign_in_with_twitter = TRUE) {
104 100
   }
105 101
 
106 102
   /**
107  
-   * Exchange the request token and secret for an access token and
  103
+   * Exchange request token and secret for an access token and
108 104
    * secret, to sign API calls.
109 105
    *
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")
112 110
    */
113 111
   function getAccessToken($oauth_verifier = FALSE) {
114 112
     $parameters = array();
@@ -122,7 +120,27 @@ function getAccessToken($oauth_verifier = FALSE) {
122 120
   }
123 121
 
124 122
   /**
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.
126 144
    */
127 145
   function get($url, $parameters = array()) {
128 146
     $response = $this->oAuthRequest($url, 'GET', $parameters);
@@ -133,7 +151,7 @@ function get($url, $parameters = array()) {
133 151
   }
134 152
   
135 153
   /**
136  
-   * POST wreapper for oAuthRequest.
  154
+   * POST wrapper for oAuthRequest.
137 155
    */
138 156
   function post($url, $parameters = array()) {
139 157
     $response = $this->oAuthRequest($url, 'POST', $parameters);
@@ -144,7 +162,7 @@ function post($url, $parameters = array()) {
144 162
   }
145 163
 
146 164
   /**
147  
-   * DELTE wrapper for oAuthReqeust.
  165
+   * DELETE wrapper for oAuthReqeust.
148 166
    */
149 167
   function delete($url, $parameters = array()) {
150 168
     $response = $this->oAuthRequest($url, 'DELETE', $parameters);

0 notes on commit 76446fa

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