0

I've been using this script to get tweets using twitter OAUTH on a local version of my website. When I upload it to my live web server it doesn't work.

It returns a JSON prettified list of twitter data based on a string that I provide.

Could anyone tell me why it isn't returning the JSON response on the live server?

<?php
session_start();
require_once("twitteroauth-master/twitteroauth/twitteroauth.php"); //Path to twitteroauth library

$notweets = 6;
$consumerkey = "**************************";
$consumersecret = "**************************";
$accesstoken = "**************************";
$accesstokensecret = "**************************";

function getConnectionWithAccessToken($cons_key, $cons_secret, $oauth_token, $oauth_token_secret) {
  $connection = new TwitterOAuth($cons_key, $cons_secret, $oauth_token, $oauth_token_secret);
  return $connection;
}

$search_term = urlencode("pizza");

$connection = getConnectionWithAccessToken($consumerkey, $consumersecret, $accesstoken, $accesstokensecret);
$tweets = $connection->get("https://api.twitter.com/1.1/search/tweets.json?q=$search_term&count=$notweets&result_type=recent&include_rts=false");

header('Content-Type: application/json');
echo json_encode($tweets, JSON_PRETTY_PRINT);

?>

SOLVED

I updated my php.ini file to display errors and was given the following message.

Use of undefined constant JSON_PRETTY_PRINT

I was then able to solve my problem. Thanks to all who commented and I learnt how to track down errors appropriately in a live PHP / server environment.

WebDevDanno
  • 1,122
  • 2
  • 22
  • 50
  • Please define what "doesn't work mean". Do you get an error? If so, which one? Is the twitteroauth-master library present on the server where you are running that script? Did you try adding `error_reporting(-1);` at the start of the script? – ArSeN Jan 05 '16 at 17:05
  • Yes. What I mean by doesn't work is there is no response printed using the "echo" command. I receive no error back. I've tried adding `error_reporting(-1);` but still no response. How can I have my script return an appropriate error message? – WebDevDanno Jan 05 '16 at 17:09
  • depending on your server configuration you may also have to `ini_set('display_errors', 'on')` right after enabling the error_reporting. If this does not help, please see this answer: http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php – ArSeN Jan 05 '16 at 17:12

0 Answers0