gpt4 book ai didi

php - Youtube 数据 API SSL 错误

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:56 25 4
gpt4 key购买 nike

我已经运行了 Youtube DATA API 的示例代码。但是,发生了与 SSL 相关的错误。

An client error occurred: SSL certificate problem: unable to get local issuer certificate

此消息由 php.ini 设置更改。

php.ini

extension=php_curl.dll => ;extension=php_curl.dll

消息:
发生客户端错误:HTTP 错误:无法连接:'fopen(compress.zlib://https://www.googleapis.com/youtube/v3/search?part=id%2Csnippet&q=aaa&maxResults=25&key={DEVELOPER_KEY}): 无法打开流:操作失败'

环境:

windows 7 pro 32bit
apache 2.4.10
php 5.4.31

源代码:

<?php

$htmlBody = <<<END
<form method="GET">
<div>
Search Term: <input type="search" id="q" name="q" placeholder="Enter Search Term">
</div>
<div>
Max Results: <input type="number" id="maxResults" name="maxResults" min="1" max="50" step="1" value="25">
</div>
<input type="submit" value="Search">
</form>
END;

// This code will execute if the user entered a search query in the form
// and submitted the form. Otherwise, the page displays the form above.
if ($_GET['q'] && $_GET['maxResults']) {
// Call set_include_path() as needed to point to your client library.
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';

/*
* Set $DEVELOPER_KEY to the "API key" value from the "Access" tab of the
* Google Developers Console <https://cloud.google.com/console>
* Please ensure that you have enabled the YouTube Data API for your project.
*/
$DEVELOPER_KEY = 'REPLACE_ME';

$client = new Google_Client();
$client->setDeveloperKey($DEVELOPER_KEY);

// Define an object that will be used to make all API requests.
$youtube = new Google_Service_YouTube($client);

try {
// Call the search.list method to retrieve results matching the specified
// query term.
$searchResponse = $youtube->search->listSearch('id,snippet', array(
'q' => $_GET['q'],
'maxResults' => $_GET['maxResults'],
));

$videos = '';
$channels = '';
$playlists = '';

// Add each result to the appropriate list, and then display the lists of
// matching videos, channels, and playlists.
foreach ($searchResponse['items'] as $searchResult) {
switch ($searchResult['id']['kind']) {
case 'youtube#video':
$videos .= sprintf('<li>%s (%s)</li>',
$searchResult['snippet']['title'], $searchResult['id']['videoId']);
break;
case 'youtube#channel':
$channels .= sprintf('<li>%s (%s)</li>',
$searchResult['snippet']['title'], $searchResult['id']['channelId']);
break;
case 'youtube#playlist':
$playlists .= sprintf('<li>%s (%s)</li>',
$searchResult['snippet']['title'], $searchResult['id']['playlistId']);
break;
}
}

$htmlBody .= <<<END
<h3>Videos</h3>
<ul>$videos</ul>
<h3>Channels</h3>
<ul>$channels</ul>
<h3>Playlists</h3>
<ul>$playlists</ul>
END;
} catch (Google_ServiceException $e) {
$htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
$htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>',
htmlspecialchars($e->getMessage()));
}
}
?>

<!doctype html>
<html>
<head>
<title>YouTube Search</title>
</head>
<body>
<?=$htmlBody?>
</body>
</html>

你能告诉我这个问题的解决方案吗?

最佳答案

我猜由于 SSLv3 协议(protocol)中的漏洞(POODLE 攻击:https://www.imperialviolet.org/2014/10/14/poodle.html),对等方可能禁用了该协议(protocol)

关于php - Youtube 数据 API SSL 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26841286/

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