我正在写一个laravel命令来阅读reddit评论。我正在运行Laravel Framework 5.2版。45。我的handle方法如下所示:
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class reddit extends Command
{
/**...**/
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$str = json_decode(file_get_contents('www.reddit.com/r/all/comments.json'));
foreach ($str as $comments) {
// dd($comments);
foreach ($comments->data->children as $comment) {
if ($comment->body_html == 'You') {
print_r($comment);
} else {
print_r($comment);
}
}
}
}
}
执行命令时,我收到以下错误消息:
[ErrorException]
文件获取内容(www.reddit.com/r/all/comments.json):无法打开流:没有这样的文件或目录
有什么建议我做错了吗?
谢谢你的回复!
使用以下URLreddit进行更新。com/r/all/comments。json
我得到:
[ErrorException]
file_get_contents(reddit.com/r/all/comments.json): failed to open stream: No such file or directory
异常跟踪:()位于/home/ubuntu/workspace/app/Console/Commands/reddit。php:55\Foundation\Bootstrap\HandleExceptions-
试试这个,对我有用:307内部重定向
on
http://www.reddit.com/r/all/comments.json
试试这个:
print_r(file_get_contents("https://www.reddit.com/r/all/comments.json"));