【发布时间】:2016-03-14 18:16:12
【问题描述】:
在我的 laravel 项目中更新我的流时遇到了一个小问题,我正在尝试定义流媒体是否是实时的,如果他们不在我的应用程序中,则隐藏它们但是当有一个流媒体不是实时的它给了我..
Trying to get property of non-object
我的 cronjob 回发看起来像这样:
$twitch_api = json_decode(file_get_contents('https://api.twitch.tv/kraken/streams/'.$stream->channel));
if($twitch_api->stream == null) $live = 0;
else $live = 1;
$update = Streams::where('id', $stream->id)->firstOrFail();
$update->thumb = $twitch_api->stream->preview->large;
$update->game = $twitch_api->stream->channel->game;
$update->status = $live;
$update->save();
Twitch API 在离线时会显示这个...
{"stream":null,"_links":{"self":"https://api.twitch.tv/kraken/streams/chan","channel":"https://api.twitch.tv/kraken/channels/chan"}}
知道为什么它给了我非对象吗?
谢谢!
【问题讨论】:
-
我怀疑
"stream":null和$twitch_api->stream->preview会让你感到不适。 (因为null不是对象。) -
感谢 HPierce,就是这样。我为预览和游戏做了一个 if 语句,现在它就像一个魅力。再次感谢=D
标签: php api laravel postback twitch