php - Twitter API returns error 215, Bad Authentication Data -


i trying call following twitter's api list of followers user.

http://api.twitter.com/1.1/followers/ids.json?cursor=-1&screen_name=username

and getting error message in response.

{     code = 215;     message = "bad authentication data"; } 

i can't seem find documentation related error code. has idea error?

a concise code without other php file include of oauth etc. please note obtain following keys need sign https://dev.twitter.com , create application.

<?php $token = 'your_token'; $token_secret = 'your_token_secret'; $consumer_key = 'consumer_key'; $consumer_secret = 'consumer_secret';  $host = 'api.twitter.com'; $method = 'get'; $path = '/1.1/statuses/user_timeline.json'; // api call path  $query = array( // query parameters     'screen_name' => 'twitterapi',     'count' => '5' );  $oauth = array(     'oauth_consumer_key' => $consumer_key,     'oauth_token' => $token,     'oauth_nonce' => (string)mt_rand(), // stronger nonce recommended     'oauth_timestamp' => time(),     'oauth_signature_method' => 'hmac-sha1',     'oauth_version' => '1.0' );  $oauth = array_map("rawurlencode", $oauth); // must encoded before sorting $query = array_map("rawurlencode", $query);  $arr = array_merge($oauth, $query); // combine values sort  asort($arr); // secondary sort (value) ksort($arr); // primary sort (key)  // http_build_query automatically encodes, our parameters // encoded, , must point, undo // encoding step $querystring = urldecode(http_build_query($arr, '', '&'));  $url = "https://$host$path";  // mash text hash $base_string = $method."&".rawurlencode($url)."&".rawurlencode($querystring);  // same key $key = rawurlencode($consumer_secret)."&".rawurlencode($token_secret);  // generate hash $signature = rawurlencode(base64_encode(hash_hmac('sha1', $base_string, $key, true)));  // time we're using normal query, , we're encoding query params // (without oauth params) $url .= "?".http_build_query($query); $url=str_replace("&amp;","&",$url); //patch @frewuill  $oauth['oauth_signature'] = $signature; // don't want abandon work! ksort($oauth); // not necessary, twitter's demo  // not necessary, twitter's demo function add_quotes($str) { return '"'.$str.'"'; } $oauth = array_map("add_quotes", $oauth);  // full value of authorization line $auth = "oauth " . urldecode(http_build_query($oauth, '', ', '));  // if you're doing post, need skip building above // , instead supply query parameters curlopt_postfields $options = array( curlopt_httpheader => array("authorization: $auth"),                   //curlopt_postfields => $postfields,                   curlopt_header => false,                   curlopt_url => $url,                   curlopt_returntransfer => true,                   curlopt_ssl_verifypeer => false);  // our business $feed = curl_init(); curl_setopt_array($feed, $options); $json = curl_exec($feed); curl_close($feed);  $twitter_data = json_decode($json);   foreach ($twitter_data &$value) {    $tweetout .= preg_replace("/(http:\/\/|(www\.))(([^\s<]{4,68})[^\s<]*)/", '<a href="http://$2$3" target="_blank">$1$2$4</a>', $value->text);    $tweetout = preg_replace("/@(\w+)/", "<a href=\"http://www.twitter.com/\\1\" target=\"_blank\">@\\1</a>", $tweetout);    $tweetout = preg_replace("/#(\w+)/", "<a href=\"http://search.twitter.com/search?q=\\1\" target=\"_blank\">#\\1</a>", $tweetout); }  echo $tweetout;  ?> 

regards


Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

php - MySQLi multi_query results for later use -