Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
PHP error empty response

The php code below should work however, I receive an error, empty response, from my server. Ive tried shutting down firewall but no luck. Can you please help me I have been trying different methods for ages I have no idea whats wrongs. Thank you.

  <?php 
require_once('TwitterAPIExchange.php');

/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
    'oauth_access_token' => "",
    'oauth_access_token_secret' => "",
    'consumer_key' => "",
    'consumer_secret' => ""

);


$url = "https://api.twitter.com/1.1/search/tweets.json";

$requestMethod = "GET";

$getfield = '?q=cloud%20computing&count=5&result_type=popular';


$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();


 ?>
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

you need to use json_decode : http://php.net/manual/en/function.json-decode.php

<?php

error_reporting(E_ALL);
ini_set("display_errors", 1);

require_once('TwitterAPIExchange.php');

$settings = array(
'oauth_access_token' => "xxx",
'oauth_access_token_secret' => "xxx",
'consumer_key' => "xxx",
'consumer_secret' => "xxx"
);

$url = "https://api.twitter.com/1.1/search/tweets.json";

$requestMethod = "GET";

$getfield = '?q=cloud%20computing&count=5&result_type=popular';
$twitter = new TwitterAPIExchange($settings);
$response = $twitter->setGetfield($getfield)
         ->buildOauth($url, $requestMethod)
         ->performRequest();

$string = json_decode($response, true); // there you handle twitter response
print_r($string); // here is the echo'd result, not needed after

// from here, you have access to the data
// then, a foreach loop will give you access to whatever you want to echo

foreach($string['statuses'] as $tweets) {
$tweet = $tweets['text'];
echo "<p>Tweet: $tweet </p>";    
}
?>

updated with the loop example

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!