/**
  * Get 'enduring' access token and secret
  * @param string, token returned by Twitter
  * @return associative array with keys: oauth_token, oauth_token_secret, screen_name
  *   or error message string
  */
 public function getAuthority($verifier)
 {
     try {
         $results = $this->request('https://api.twitter.com/oauth/access_token', 'POST', array('oauth_verifier' => $verifier));
     } catch (TwitterException $e) {
         return $e->getMessage();
     }
     if ($results) {
         $token = Twitter_OAuthUtil::parse_parameters($results);
         if (is_array($token) && isset($token['oauth_token'])) {
             unset($token['user_id']);
             return $token;
         }
     }
     return 'Twitter authority-request failed';
 }
Esempio n. 2
0
 public static function build_http_query($params)
 {
     if (!$params) {
         return '';
     }
     // Urlencode both keys and values
     $keys = Twitter_OAuthUtil::urlencode_rfc3986(array_keys($params));
     $values = Twitter_OAuthUtil::urlencode_rfc3986(array_values($params));
     $params = array_combine($keys, $values);
     // Parameters are sorted by name, using lexicographical byte value ordering.
     // Ref: Spec: 9.1.1 (1)
     uksort($params, 'strcmp');
     $pairs = array();
     foreach ($params as $parameter => $value) {
         if (is_array($value)) {
             // If two or more parameters share the same name, they are sorted by their value
             // Ref: Spec: 9.1.1 (1)
             // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
             sort($value, SORT_STRING);
             foreach ($value as $duplicate_value) {
                 $pairs[] = $parameter . '=' . $duplicate_value;
             }
         } else {
             $pairs[] = $parameter . '=' . $value;
         }
     }
     // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
     // Each name-value pair is separated by an '&' character (ASCII code 38)
     return implode('&', $pairs);
 }