gpt4 book ai didi

php - 如何组合功能以获取多种类型的信息

转载 作者:行者123 更新时间:2023-12-03 06:18:38 24 4
gpt4 key购买 nike

我使用Youtube Api来获取有关单个视频的信息。当我使用类似网址的请求时:

https://www.googleapis.com/youtube/v3/videos?part=status,snippet,contentdetails&id=$videoID&key=$apikey

我得到了我需要的所有信息。问题是我无法找到一种方法来一次性组合获得信息所需的功能。

我到目前为止所得到的:
function getDescription($videoID){
$apikey = "<MYKEY>";

$desc = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$videoID&key=$apikey");
$description =json_decode($desc, true);
foreach ($description['items'] as $videodesc)
{
$description= $videodesc['snippet']['description'];
}
return $description;
}

function getPublishedAt($videoID){
$apikey = "<MYKEY>";

$pub = file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet&id=$videoID&key=$apikey");
$publish =json_decode($pub, true);
foreach ($publish['items'] as $published)
{
$publish= $published['snippet']['publishedAt'];
}

$publish = new DateTime($publish);
$publish = $publish->format('Y-m-d H:i:s');

return $publish;

}

echo "<br>Description: ";
echo getDescription("<VIDEO-ID>");
echo "<br>PublishedAt: ";
echo getPublishedAt("<VIDEO-ID>");

因此,此代码有效,但是我想向api发出一个请求(使用url中的多个部分)并获取信息。

有谁知道如何仅使用一个功能执行此操作?

最佳答案

好吧,我自己找到了答案:

$videoinfo = file_get_contents("https://www.googleapis.com/youtube/v3/videos?id=<video-id>&part=snippet,status,contentDetails,statistics&part=statistics&key=<api-key>");
$videoinfo =json_decode($videoinfo, true);
foreach ($videoinfo['items'] as $embed)
{
$emb= $embed['status']['embeddable'];
$license= $embed['status']['license'];
$duration= $embed['contentDetails']['duration'];
}
echo $emb;
echo $license;
echo $duration;

这不是一个函数,但这将执行公制:)

关于php - 如何组合功能以获取多种类型的信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39589204/

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