J7mbo / twitter-api-php

The simplest PHP Wrapper for Twitter API v1.1 calls
MIT License
1.82k stars 802 forks source link

TwitterAPIExchange.php error at Line [ throw new \Exception($error); ] #208

Closed ashnashamim17 closed 7 years ago

ashnashamim17 commented 7 years ago

I am making PHP application for fetching twitter data using Xampp I am using your TwitterAPIExchange when run the code

it shows this error [Fatal error: in C:\xampp\htdocs\twitter\TwitterAPIExchange.php on line 315] if (($error = curl_error($feed)) !== ”) { curl_close($feed);

throw new \Exception($error); }

curl_close($feed);

return $json; Line 315: throw new \Exception($error);

code that I am coding is:

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

/\ Set access tokens here - see: https://dev.twitter.com/apps/ **/ $settings = array( 'oauth_access_token' => "765596413539545088-hPJ1seD2ZKz2eqcPPa0l2YhjvoT2mKv", 'oauth_access_token_secret' => "UpAeaZeFqZ8XIB6yKRn0k8m430H1hFJqNCy5iw2YfC5ow", 'consumer_key' => "J085otKXysALVxg2z7t1MjuQ3", 'consumer_secret' => "CTJNTjHeJAmVMAyOMpdu98xJkHjw253UX5CcOX0RLHnUGg2T8i" ); $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $requestMethod = "GET"; if (isset($_GET['user'])) {$user = $_GET['user'];} else {$user = "iagdotme";} if (isset($_GET['count'])) {$count = $_GET['count'];} else {$count = 20;} $getfield = "?screen_name=$user&count=$count"; $twitter = new TwitterAPIExchange($settings); $string = json_decode($twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(),$assoc = TRUE); if($string["errors"][0]["message"] != "") {echo "

Sorry, there was a problem.

Twitter returned the following error message:

".$string[errors][0]["message"]."

";exit();} foreach($string as $items) { echo "Time and Date of Tweet: ".$items['created_at']."
"; echo "Tweet: ". $items['text']."
"; echo "Tweeted by: ". $items['user']['name']."
"; echo "Screen name: ". $items['user']['screen_name']."
"; echo "Followers: ". $items['user']['followers_count']."
"; echo "Friends: ". $items['user']['friends_count']."
"; echo "Listed: ". $items['user']['listed_count']."

"; }

?>**` please tell me what the problem is, and how it can be solved

J7mbo commented 7 years ago

Looks like you might not have cURL enabled for your version PHP. Try checking that and enabling it? Plenty of tuts online :-)

On 23 Aug 2016, at 20:40, ashnashamim17 notifications@github.com<mailto:notifications@github.com> wrote:

I am making PHP application for fetching twitter data using Xampp I am using your TwitterAPIExchange when run the code

it shows this error [Fatal error: in C:\xampp\htdocs\twitter\TwitterAPIExchange.php on line 315] if (($error = curl_error($feed)) !== ") { curl_close($feed);

throw new \Exception($error); }

curl_close($feed);

return $json; Line 315: throw new \Exception($error);

code that I am coding is:

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

/\ Set access tokens here - see: https://dev.twitter.com/apps/ **/ $settings = array( 'oauth_access_token' => "765596413539545088-hPJ1seD2ZKz2eqcPPa0l2YhjvoT2mKv", 'oauth_access_token_secret' => "UpAeaZeFqZ8XIB6yKRn0k8m430H1hFJqNCy5iw2YfC5ow", 'consumer_key' => "J085otKXysALVxg2z7t1MjuQ3", 'consumer_secret' => "CTJNTjHeJAmVMAyOMpdu98xJkHjw253UX5CcOX0RLHnUGg2T8i" ); $url = "https://api.twitter.com/1.1/statuses/user_timeline.json"; $requestMethod = "GET"; if (isset($_GET['user'])) {$user = $_GET['user'];} else {$user = "iagdotme";} if (isset($_GET['count'])) {$count = $_GET['count'];} else {$count = 20;} $getfield = "?screen_name=$user&count=$count"; $twitter = new TwitterAPIExchange($settings); $string = json_decode($twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest(),$assoc = TRUE); if($string["errors"][0]["message"] != "") {echo "

Sorry, there was a problem.

Twitter returned the following error message:

".$string[errors][0]["message"]."

";exit();} foreach($string as $items) { echo "Time and Date of Tweet: ".$items['created_at']." "; echo "Tweet: ". $items['text']." "; echo "Tweeted by: ". $items['user']['name']." "; echo "Screen name: ". $items['user']['screen_name']." "; echo "Followers: ". $items['user']['followers_count']." "; echo "Friends: ". $items['user']['friends_count']." "; echo "Listed: ". $items['user']['listed_count']."


"; }

?>**` please tell me what the problem is, and how it can be solved

You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/J7mbo/twitter-api-php/issues/208, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACiMHu94rWID3WUkda682zrOqEXogFpHks5qi0yqgaJpZM4JrTr3.

ashnashamim17 commented 7 years ago

I have followed all the tutorials: I also Uncomment extension=php_curl.dll by removing ';' in three files inside C:/xampp/php 1.php.ini 2.php.ini-development 3.php.ini-production

please tell how should I solve this problem, I have spent couple of days figuring out the problem.. please help solving this problem @J7mbo

J7mbo commented 7 years ago

At the very top of your PHP file, put this: var_dump(extension_loaded('curl')); die; and let us know what the response is?

On 23 Aug 2016, at 21:21, ashnashamim17 notifications@github.com<mailto:notifications@github.com> wrote:

I have followed all the tutorials: I also Uncomment extension=php_curl.dll by removing ';' three files inside C:/xampp/php 1.php.ini 2.php.ini-development 3.php.ini-production

please tell how should I solve this problem, I have spent couple of days figuring out the problem.. please help solving this problem @J7mbohttps://github.com/J7mbo

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/J7mbo/twitter-api-php/issues/208#issuecomment-241864536, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ACiMHt2AAFVbDzgS7LE6ndySZUL5cRk7ks5qi1ZdgaJpZM4JrTr3.

ashnashamim17 commented 7 years ago

I gives the bool(ture) response @J7mbo

ashnashamim17 commented 7 years ago

Please tell me how to solve this problem, I am beginner in PHP development, I have no idea how it can be solved.. waiting for your reply :) @J7mbo

J7mbo commented 7 years ago

It's 10pm here so I won't be online much longer for today. Did you definitely paste the whole of the error message? It seems like there's some missing. Can you paste the exact error message on its own?

ashnashamim17 commented 7 years ago

Fatal error: in C:\xampp\htdocs\twitter\TwitterAPIExchange.php on line 315 this is the complete error msg in TwitterAPIExchange.php if (($error = curl_error($feed)) !== '') { curl_close($feed);

        **throw new \Exception($error);** <-- at this line
    }

   curl_close($feed);

    return $json;
}

, and when I commented this line it gives error msg

**Warning: curl_close(): 3 is not a valid cURL handle resource in C:\xampp\htdocs\twitter\TwitterAPIExchange.php on line 318

Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\twitter\twitterapp.php on line 44**

Line 318 :if (($error = curl_error($feed)) !== '') { curl_close($feed);

       // throw new \Exception($error);
    }

   **curl_close($feed);** <--- Line 318

    return $json;

and Line 44 is private $getfield;

ashnashamim17 commented 7 years ago

Ok If you can't reply today please reply tomorrow if possible and thanks a lot :')

J7mbo commented 7 years ago

Can you please run the example code from README.md and let me know what the result is, instead of your code?

$url = 'https://api.twitter.com/1.1/followers/ids.json';
$getfield = '?screen_name=J7mbo';
$requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
    ->buildOauth($url, $requestMethod)
    ->performRequest();
ashnashamim17 commented 7 years ago

`<?php //var_dump(extension_loaded('curl')); die;

require_once('TwitterAPIExchange.php');

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

// [example code from README.md starts ]

$url = 'https://api.twitter.com/1.1/followers/ids.json'; $getfield = '?screen_name=J7mbo'; $requestMethod = 'GET'; $twitter = new TwitterAPIExchange($settings); echo $twitter->setGetfield($getfield) ->buildOauth($url, $requestMethod) ->performRequest();

// [example code from README.md ends ] ?>`

By running the above code it displays the following error msg: Fatal error: in C:\xampp\htdocs\twitter\TwitterAPIExchange.php on line 314

Line 314: throw new \Exception($error);

In context of:

if (($error = curl_error($feed)) !== '')
      {
           curl_close($feed);
          throw new \Exception($error); <---Line 314
      }
  curl_close($feed);  <--- Line 317
   return $json;
`

@J7mbo

ashnashamim17 commented 7 years ago

Thanks your solution helps solving this problem

J7mbo commented 7 years ago

Does it?

Really I'm not being given an error, you need to step through it and var_dump($variableHere); die; just before the exception is thrown to see what it is. That may help us. It's just debugging.

J7mbo commented 7 years ago

I'm closing this as it's an old issue but if you still need help with anything please feel free to open a new one.

satarfatar commented 7 years ago

@ashnashamim17 hi could you please tell how you resolved this [bool(true)] message, I'm getting the same message