所以我是php的新手,我试图让这个代码从twitter的api获取用户计时器,然后将它们发布到我制作的html网站上。我将所有代码都连接到WAMP。我只想让它在本地运行,但我一直遇到错误,因为我的生活我无法理解这一点?
这是我试图用HTML实现的代码
<?php
require_once('TwitterAPIExchange.php');
/** Set access tokens here - see: https://dev.twitter.com/apps/ **/
$settings = array(
'oauth_access_token' => "YOUR_OAUTH_ACCESS_TOKEN",
'oauth_access_token_secret' => "YOUR_OAUTH_ACCESS_TOKEN_SECRET",
'consumer_key' => "YOUR_CONSUMER_KEY",
'consumer_secret' => "YOUR_CONSUMER_SECRET"
);
$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 "<h3>Sorry, there was a problem.</h3><p>Twitter returned the following error message:</p><p><em>".$string[errors][0]["message"]."</em></p>";exit();}
foreach($string as $items)
{
echo "<h4>Time and Date of Tweet</h4>: ".$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 />";
}
?>
&#13;
这是我不断得到的错误
(!)警告:第23行的C:\ wamp64 \ www \ php \ Usertimeline.php中为foreach()提供的参数无效 调用堆栈
1 0.0023 248512 {main}()... \ Usertimeline.php:0
请帮助我!!