Thursday, 15 July 2010

php - Twitter oAuth: getting an error 215 -



php - Twitter oAuth: getting an error 215 -

i have next code in 1 of classes:

public function build_httpheader ($options = null) { if (!$this->oauth_token && !$this->oauth_token_secret && !$this->http_method) { throw new exception('the oauth_token, oauth_token_secret , http method must set'); } $url = $this->base_uri; $url_curl = $this->base_uri; if ($options) { $this->options = $options; $url .= '?'; $url_curl .= '?'; $count = count($options); foreach($options $key => $value) { $count = $count--; if ($count) { $url .= '&'.$key.'='.$value; $url_curl .= '&'.$key.'='.rawurlencode($value); } else { $url .= $key.'='.$value; $url_curl .= $key.'='.rawurlencode($value); } } } $this->url = $url_curl; /** * @internal create 32 chars unique string * utilize nonce value */ list($usec, $sec) = explode(" ", microtime()); $usec = str_replace('0.', '', $usec); $nonce_str = utf8_encode($sec.$usec.'abcd'.$sec); $oauth_nonce = md5($nonce_str); /** * @internal create initial oauth array */ $oauth = array ( 'oauth_consumer_key' => $this->consumer_key, 'oauth_nonce' => $this->$oauth_nonce, 'oauth_signature_method' => 'hmac-sha1', 'oauth_token' => $this->oauth_token, 'oauth_timestamp' => time(), 'oauth_version' => '1.0' ); /** * @internal generate basic info */ $t_oauth = array(); ksort($oauth); foreach($oauth $key=>$value){ $t_oauth[] = "$key=" . rawurlencode($value); } $base_info = $this->http_method."&" . rawurlencode($url) . '&' . rawurlencode(implode('&', $t_oauth)); $composite_key = rawurlencode($this->consumer_secret) . '&' . rawurlencode($this->oauth_token_secret); $oauth['oauth_signature'] = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true)); $oauth_string = 'authorization: oauth '; $values = array(); foreach($oauth $key=>$value) { $values[] = "$key=\"" . rawurlencode($value) . "\""; } $oauth_string .= implode(', ', $values); $this->http_headers = array ($oauth_string, 'expect:'); } public function tw_curl_api_call () { $ch = curl_init(); curl_setopt($ch, curlopt_httpheader, $this->http_headers); if ($this->http_method == 'post') { curl_setopt($ch, curlopt_post, true); } if ( ($this->http_method != 'post') && ($this->http_method != 'get') ) { curl_setopt($ch, curlopt_customrequest, $this->http_method); } curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_url, $this->url); curl_setopt($ch, curlopt_returntransfer, 1); curl_setopt($ch, curlopt_ssl_verifypeer, 0); curl_setopt($ch, curlopt_ssl_verifyhost, 0); curl_setopt($ch, curlopt_followlocation, 0); $result = json_decode(curl_exec($ch), true); $info = curl_getinfo($ch); curl_close($ch); homecoming array ('result' => $result, 'info' => $info); }

another script uses class follows:

$options = array ('resources' => 'help,users,search,statuses'); $tw_wrapper->build_httpheader ($options); $results = $tw_wrapper->tw_curl_api_call ();

i getting error 215 (bad authentication data). ideas (i aware there existing php oauth classes , twitter wrappers, not seem if of them has migrated 1.1 api).

have had @ codebird? has back upwards 1.1 , works i've needed. ymwv of course.

a simple example:

codebird::setconsumerkey('key', 'secret'); $cb = codebird::getinstance(); $cb->settoken('auth_key', 'auth_secret'); $result = $cb->statuses_usertimeline(array( 'include_rts' => true, 'screen_name' => 'hansnilsson', ));

php oauth twitter

No comments:

Post a Comment