Problems with Twitter API 1.1 - application-only authentication response


I’m trying to retrieve data from Twitter by connecting to its API and make some requests but I always get nothing in return… I just requested the bearer token and successfully received it.

Here is the code in PHP:

$url = “”;
$headers = array(
“GET”.$url." HTTP/1.1",
“User-Agent: My Twitter App v1.0.23”,
“Authorization: Bearer “.$bearer_token.””,
“Content-Type: application/x-www-form-urlencoded;charset=UTF-8”,

$ch = curl_init(); // setup a curl
curl_setopt($ch, CURLOPT_URL,$url); // set url to send to
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); // set custom headers
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // return output
$retrievedhtml = curl_exec ($ch); // execute the curl


Here is another way I have tried but also I got the same results

    $url = "";

$context = stream_context_create(array("https" => array("method" => "GET",
        "header" => "GET /1.1/statuses/user_timeline.json?count=100&screen_name=twitterapi HTTP/1.1 \r\n" .
        "Host: \r\n" .
        "User-Agent: My Twitter App v1.0.23 \r\n" .
        "Authorization: Bearer " . $bearer_token . "\r\n" .
        "Accept-Encoding: gzip \r\n"  )));

     $data = @file_get_contents($url, true, $context);
     $respone= json_decode($data, true);

when using the print_r nothing is shown at all and when using the var_dump i found “bool(false)”

Any idea with what could be wrong with this?



Ashraf —

Were you able to successfully make requests to this API endpoint using twurl ( That’s usually a good way to diagnose the issue; if you are able to make calls using Twurl, then there is likely something amiss with your code. You use the headers and responses from Twurl to debug your code.