Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/238.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php TwitterAPI不在循环中工作_Php_Twitter - Fatal编程技术网

Php TwitterAPI不在循环中工作

Php TwitterAPI不在循环中工作,php,twitter,Php,Twitter,我正在使用下面的api来填充下面的循环,该循环运行良好 $tweets = $twitter->get('https://api.twitter.com/1.1/search/tweets.json?q='.$queryString.'&count=400'); <?php foreach ($tweets->statuses as $key => $tweet) { ?> <?=$tweet->name; ?><br/>

我正在使用下面的api来填充下面的循环,该循环运行良好

 $tweets = $twitter->get('https://api.twitter.com/1.1/search/tweets.json?q='.$queryString.'&count=400');

 <?php foreach ($tweets->statuses as $key => $tweet) { ?>
 <?=$tweet->name; ?><br/>
 <img src="<?=$tweet->user->profile_image_url;?>" />
 <?=$tweet->text; ?>
但要继续犯这个错误 警告:为foreach()提供的参数无效

我想我已经对foreach做了一些更改,但我不知道该更改什么


谢谢。

要循环查看主时间线请求的结果,请尝试以下操作(未测试):

$tweets=$twitter->get('https://api.twitter.com/1.1/statuses/home_timeline.json?count=400');

用户->配置文件\图像\ url;?>" />

我还更改了
home\u timeline
的API URL,因为它不接受查询字符串(与我发布的文档链接相同)。相反,它将为当前经过身份验证的用户提取时间线。

要循环查看
home\u timeline
请求的结果,请尝试以下操作(未测试):

$tweets=$twitter->get('https://api.twitter.com/1.1/statuses/home_timeline.json?count=400');

用户->配置文件\u图像\u url;?>“/>

我还更改了
home\u timeline
的API URL,因为它不接受查询字符串(与我发布的文档链接相同)。相反,它将为当前经过身份验证的用户提取时间线。

尝试在
home\u时间线
请求上执行
var\u dump($tweets)
,以查看返回内容
为foreach()提供的参数无效。
意味着变量
$tweets->status
不是
foreach
可以循环的数组。实际上,
home\u timeline
结果将返回一组tweets,因此没有
status
对象。看看这个页面,特别是示例结果:@JakeB。谢谢,我已经通读了一遍,我理解为什么它不起作用。请告诉我如何循环结果?我将在下面发布完整答案。尝试在
home\u时间轴上执行
var\u dump($tweets)
,以查看返回结果
为foreach()提供的参数无效。
意味着变量
$tweets->status
不是
foreach
可以循环的数组。实际上,
home\u timeline
结果将返回一组tweets,因此没有
status
对象。看看这个页面,特别是示例结果:@JakeB。谢谢,我已经通读了一遍,我理解为什么它不起作用。请告诉我如何循环结果?我将在下面发布完整答案。
$tweets = $twitter->get('https://api.twitter.com/1.1/statuses/home_timeline.json?q='.$queryString.'&count=400');
$tweets = $twitter->get('https://api.twitter.com/1.1/statuses/home_timeline.json?count=400');

 <?php foreach ($tweets as $key => $tweet) { ?>
 <?=$tweet->user->name; ?><br/>
 <img src="<?=$tweet->user->profile_image_url;?>" />
 <?=$tweet->text; ?>