Youtube api 获取Laravel Youtube API中的奇怪错误
我正在使用Laravel5.6和这个youtube api 我正试图用这样的页码搜索结果Youtube api 获取Laravel Youtube API中的奇怪错误,youtube-api,laravel-5.6,Youtube Api,Laravel 5.6,我正在使用Laravel5.6和这个youtube api 我正试图用这样的页码搜索结果 $params = [ 'q' => $request, 'type' => 'video', 'part' => 'id, snippet', 'maxResults' => 20 ]; // $search = Youtube::s
$params = [
'q' => $request,
'type' => 'video',
'part' => 'id, snippet',
'maxResults' => 20
];
// $search = Youtube::searchAdvanced($params, true);
$search = Youtube::paginateResults($params, null);
$info = $search['info'];
$nextpagetoken = $info['nextPageToken'];
return view('search.index', compact('search'));
我的看法呢
@foreach($search as $result)
@foreach($result as $video)
{{ dd($video->snippet->title) }}
@endforeach
@endforeach
我的成绩
但问题是当我使用{{$video->snippet->title}}
获取错误时
您试图将标题作为对象访问,但它是一个数组 我会尝试一些类似于: $video->snippet['title'] (很抱歉没有使用降价语法,我正在使用智能手机回答此问题)
我猜dd()足够聪明,可以知道两者之间的区别,并正确地显示两者。当我
dd($search)时代码>检查我得到2个数组
array:2 [▼
"results" => array:20 [▶]
"info" => array:6 [▶]
]
所以我用
$results = $search['results'];// for videos only
$info = $search['info']; // For Other info's
现在我可以在视图中使用foreach
@foreach($results as $video)
<div class="row boxhead">
<div class="col-md-4">
<a href="{{ url('watch/' . $video->id->videoId)}}">
<img src="{{$video->snippet->thumbnails->medium->url}}" class="img-fluid">
</a>
</div>
<div class="col-md-8">
<a href="#">
<h1 style="font-size: 17px;">{{ $video->snippet->title }}</h1>
<p>{{ $video->snippet->channelTitle }}</p>
<p>{{ $video->snippet->description }}</p>
</a>
</div>
</div>
<hr>
@endforeach
@foreach($results as$video)
@endforeach
它工作正常为什么要显示错误消息的图片?@tehhowch用于显示实际错误,我不理解这意味着代码片段为空或属性标题不存在。但是当我使用dd()代码>它向我显示结果你必须检查$search包含的内容,你能在这里发布图像并用ddi修复它但不是那样谢谢你回答我不客气,我们至少想知道解决方案背后的原理:)我添加了我的答案