0

I have a PHP script that displays Tweets embedded in a site I built out on my local machine. When I uploaded the site to my IIS 8.0 server, the PHP script no longer works and I receive this error:

Warning: Invalid argument supplied for foreach() in C:\inetpub\wwwroot\i360_new\footer.php on line 76

The script is:

<?php
    ini_set('display_errors', 1);
    require_once('TwitterAPIExchange.php');

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


    /** Perform a GET request and echo the response **/
    /** Note: Set the GET field BEFORE calling buildOauth(); **/
    $url = "https://api.twitter.com/1.1/statuses/user_timeline.json";
    $getfield = '?screen_name=interactive360&count=1';
    $requestMethod = 'GET';
    $twitter = new TwitterAPIExchange($settings);
    $string = json_decode($twitter->setGetfield($getfield)
    ->buildOauth($url, $requestMethod)
    ->performRequest(),$assoc = TRUE);
    foreach($string as $items)
        {
            echo $items['text']."<br />";
        }
?>

I thought it might be a PHP version issue but my local machine is running 5.4.10 and my server is running 5.4.14.

3 Answers3

1

Did you compare both servers phpinfo()? While running in almost the same environment each server can work differently depending on which modules are installed.

kworr
  • 1,085
0

You might want to make sure that the $string isn't empty. I believe a ForEach will throw this error if you provide a string that is empty. It looks like the string depends on TwitterAPIExchange.php, I see the 'Require Once', but ensure it's configured correctly.

Noobixide
  • 126
0

It turns out this was an SSL/CURL issue. In the TwitterAPIExchange.php file, I had to add these two lines to the CURL options array:

CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false