这是应用程序从 Twitter 用户那里检索数据的代码。我正在使用 TwitterAPIExchange api 库。调用失败,false
而是返回 boolean - var_dump($string)
prints bool(false)
。
我也不知道为什么当我运行代码时我没有得到任何检索到的数据,即输出是空白的。
<?php
require_once('TwitterAPIExchange.php');
$settings = array(
'oauth_access_token' => "",
'oauth_access_token_secret' => "",
'consumer_key' => "",
'consumer_secret' => ""
);
$url = "https://api.twitter.com/1.1/statuses/mentions_timeline.json";
$requestMethod = "GET";
if (isset($_GET['user'])) {
$user = $_GET['user'];
} else {
$user = "lestaaaaaaa";
}
if (isset($_GET['count'])) {
$count = $_GET['count'];
} else {
$count = 20;
}
$getfield = "?screen_name=".$user."&count=".$count;
$twitter = new TwitterAPIExchange($settings);
$string = $twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest();
var_dump($string);
if (is_array($string))
{
foreach($string as $items)
{
echo "Time and Date of Tweet: ".$items['created_at']."<br />";
echo "Tweet: ". $items['text']."<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 />";
}
}
print_r($string);
?>