php - Oauth header issue with twitter api 1.1 -


i've been trying access new twitter api (1.1) 3 days now, new oauth system , not compatible. want grab 3 of latest tweets (which public why need oauth on simple rss annoying)

<?php  $header = 'get /statuses/user_timeline.json?screen_name=name&count=3&include_rts=false http/1.1 host: https://www.twtter.com:443 authorization: oauth realm="https://https://www.twtter.com/statuses/user_timeline.json",     oauth_consumer_key="key",     oauth_token="mytoken",     oauth_nonce="",     oauth_timestamp="0",     oauth_signature_method="hmac-sha1",     oauth_version="1.0",     oauth_signature="o4yjhqnylxmp5u97rj%2f4uuljh84%3d"';  $url = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=name&count=3&include_rts=false";  $options = array(              curlopt_httpheader => $header,             curlopt_header => false,             curlopt_url => $url,             curlopt_returntransfer => true,             curlopt_ssl_verifypeer => false         );          $feed = curl_init();         curl_setopt_array($feed, $options);         $json = curl_exec($feed);         curl_close($feed); ?> 

the header seems problem ( generated using: http://hueniverse.com/oauth/guide/authentication/ )

name, mytoken, key placeholders posts' sake.

can see problem is?

this use. call returntweet()

for more info 'user_timeline', visit api documentation

function buildbasestring($baseuri, $method, $params) {     $r = array();     ksort($params);     foreach($params $key=>$value){         $r[] = "$key=" . rawurlencode($value);     }     return $method."&" . rawurlencode($baseuri) . '&' . rawurlencode(implode('&', $r)); }  function buildauthorizationheader($oauth) {     $r = 'authorization: oauth ';     $values = array();     foreach($oauth $key=>$value)         $values[] = "$key=\"" . rawurlencode($value) . "\"";     $r .= implode(', ', $values);     return $r; }      function returntweet(){         $oauth_access_token         = "xxx";         $oauth_access_token_secret = "xxx";         $consumer_key               = "xxx";         $consumer_secret            = "xxx";          $twitter_timeline           = "user_timeline";  //  mentions_timeline / user_timeline / home_timeline / retweets_of_me          //  create request             $request = array(                 'trim_user'     => 1,                 'screen_name'   => 'budidino',                 'count'         => '3'             );          $oauth = array(             'oauth_consumer_key'        => $consumer_key,             'oauth_nonce'               => time(),             'oauth_signature_method'    => 'hmac-sha1',             'oauth_token'               => $oauth_access_token,             'oauth_timestamp'           => time(),             'oauth_version'             => '1.0'         );          //  merge request , oauth 1 array             $oauth = array_merge($oauth, $request);          //  magic             $base_info              = buildbasestring("https://api.twitter.com/1.1/statuses/$twitter_timeline.json", 'get', $oauth);             $composite_key          = rawurlencode($consumer_secret) . '&' . rawurlencode($oauth_access_token_secret);             $oauth_signature            = base64_encode(hash_hmac('sha1', $base_info, $composite_key, true));             $oauth['oauth_signature']   = $oauth_signature;          //  make request             $header = array(buildauthorizationheader($oauth), 'expect:');             $options = array( curlopt_httpheader => $header,                               curlopt_header => false,                               curlopt_url => "https://api.twitter.com/1.1/statuses/$twitter_timeline.json?". http_build_query($request),                               curlopt_returntransfer => true,                               curlopt_ssl_verifypeer => false);              $feed = curl_init();             curl_setopt_array($feed, $options);             $json = curl_exec($feed);             curl_close($feed);          return json_decode($json, true);     } 

i hope helps ;)


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -