gpt4 book ai didi

php - fatal error : Uncaught TypeError: Cannot access offset of type string on string

转载 作者:行者123 更新时间:2023-12-05 03:44:15 27 4
gpt4 key购买 nike

<分区>

我正在尝试创建一个网站并使用 YouTube API 来显示我的 YouTube channel 最近上传的两个视频。视频显示正确,但下方显示以下错误。

Fatal error: Uncaught TypeError: Cannot access offset of type string on string in D:\xampp\htdocs\ImperialSoundsWebsite\index.php:95 Stack trace: #0 {main} thrown in D:\xampp\htdocs\ImperialSoundsWebsite\index.php on line 95

第 95 行代码是:

echo '<iframe width="1280" height="720" src="https://www.youtube.com/embed/' . $video['v_id'] .'" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';

全套代码:

<!DOCTYPE html>
<title>Home</title>
<html>
<header>
<meta charset="utf-8" />

<!--Link to style sheet-->
<link rel="stylesheet" href="stylesheet.css">
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap" rel="stylesheet">


<div class="box-area">
<div class="wrapper">
<div class="logo">
<a href="#">Imperial Sounds</a>
</div>
<nav>
<a href="index.php">Home</a>
<a href="genres.php">Genres</a>
<a href="submityourmusic.php">Submit Your Music!</a>
<a href="about.php">About Us/Contact</a>
</nav>
</div>
</div>
</header>
<body>

<div class="banner-area">
<h2>Imperial Sounds Music</h2>
<h3 style="color: white; font-family: poppins;">Home for the latest and best copyright free music!</h3>
</div>

<div class="wrapper">
<div class="our-story">
<h2>Our Story</h2>
</div>
</div>

<div class="content-area">
<div class="content-img">
<img src="images/logos/youtubeicon.jpg" alt="icon" />
</div>
<div class="wrapper">
<p style="color: black; font-family: poppins; font-size: 28px; font-weight: bold;">Our Story</p>
<p style="color: black; font-family: poppins; font-size: 20px; display:inline">Imperial Sounds is a Digital Copyright Free Music Promotor. We share a wide range of different genres of music to suit many different needs for music producers and content creators.</p>
</div>

<div id="channel-data" class="col s6">
</div>

<div class="row" id="video-container">

<?php

$API_Url = 'https://www.googleapis.com/youtube/v3/';
$API_Key = 'AIzaSyCZZHuMnTS8q2hXs_-aeEl_lEJcNOX3mlg';

$channelId = 'UCk7cEDiU2CzRAgEmTUciK1A';

$parameter = [
'id'=> $channelId,
'part'=> 'contentDetails',
'key'=> $API_Key
];
$channel_URL = $API_Url . 'channels?' . http_build_query($parameter);
$json_details = json_decode(file_get_contents($channel_URL), true);

$playlist = $json_details['items'][0]['contentDetails']['relatedPlaylists']['uploads'];

$parameter = [
'part'=> 'snippet',
'playlistId' => $playlist,
'maxResults' => '2',
'key'=> $API_Key
];
$channel_URL = $API_Url . 'playlistItems?' . http_build_query($parameter);
$json_details = json_decode(file_get_contents($channel_URL), true);

$my_videos = [];
foreach($json_details['items'] as $video){
//$my_videos[] = $video['snippet']['resourceId']['videoId'];
$my_videos[] = array( 'v_id'=>$video['snippet']['resourceId']['videoId'],
'v_name'=>$video['snippet']['title'] );
}

while(isset($json_details['nextPageToken'])){
$nxt_page_URL = $channel_URL . '&pageToken=' . $json_details['nextPageToken'];
$json_details = json_decode(file_get_contents($nxt_page_URL), true);
foreach($json_details['items'] as $video)
$my_videos[] = $video['snippet']['resourceId']['videoId'];
}

//print_r($my_videos);
foreach($my_videos as $video){
echo '<iframe width="1280" height="720" src="https://www.youtube.com/embed/' . $video['v_id'] .'" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>';
}
?>

</div>
</body>
</html>

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com