Reputation: 397
I've looked all over for some help finding a solution but I just can't find it. I know I have entered the tokens and keys correctly and set the permissions correctly for my app. I am completely stuck
<?php
require_once("TwitterAPIExchange.php");
$settings = array(
"oauth_access_token" => "2417489002-zSklTBdkf0qidQQZq3TiEa2IlAxh6lu5aCG988G",
"oauth_access_token_secret" => "VTY7I731dDJfcs3myeKp14TIewUI73tDB62Z8Cncbl46o",
"consumer_key" => "bYKS1A8gKcVF7LFy0ZaSWR8J6",
"consumer_secret" => " UCakq879nUFQe6HCHCiXRj4ZThFOFsADvAx95oD5xglpXau1Ra"
);
$url = "https://api.twitter.com/1.1/search/tweets.json?q=propane";
$requestMethod = "GET";
$getfield = "?screen_name=iagdotme&count=20";
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(), $assoc = TRUE);
if($string["errors"][0]["message"] != "") {
echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error messsage:
</p><p><em>".$string[errors][0]["message"]."</em></p>";
exit();
}
foreach($string as $items) {
echo "Time and Date of Tweet: ".$items['created_at']."<br/>";
echo "Tweet: ".$items["user"]["name"]."<br/>";
echo "Tweeted by: ".$items["user"]["name"]."<br/>";
echo "Screen name: ".$items["user"]["screen_name"]."<br/>";
echo "Followers: ".$items["user"]["followers_count"]."<br/>";
echo "Friends: ".$items["user"]["friends_count"]."<br />";
echo "Listed: ".$items["user"]["listed_count"]."<br /><hr />";
}
?>
Upvotes: 3
Views: 765
Reputation: 5886
You can't have a query string in the URL and also call setGetfield
. Move the query parameters all in to setGetfield
.
Iterate over $string["statuses"]
instead of $string
.
After these modifications, the resulting code is:
$url = "https://api.twitter.com/1.1/search/tweets.json";
$requestMethod = "GET";
$getfield = "?q=propane&screen_name=iagdotme&count=20";
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(), $assoc = TRUE);
if($string["errors"][0]["message"] != "") {
echo "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error messsage:
</p><p><em>".$string[errors][0]["message"]."</em></p>";
exit();
}
foreach($string["statuses"] as $items) {
echo "Time and Date of Tweet: ".$items['created_at']."<br/>";
echo "Tweet: ".$items["user"]["name"]."<br/>";
echo "Tweeted by: ".$items["user"]["name"]."<br/>";
echo "Screen name: ".$items["user"]["screen_name"]."<br/>";
echo "Followers: ".$items["user"]["followers_count"]."<br/>";
echo "Friends: ".$items["user"]["friends_count"]."<br />";
echo "Listed: ".$items["user"]["listed_count"]."<br /><hr />";
}
Upvotes: 1