php - 带有消息 'Protocol "https 的 Google 服务身份验证 Google_IO_Exception 在 libcurl 中不受支持或禁用

标签 php api youtube

我正在使用 Youtube 数据 API,它可以在本地主机上正常工作,但是当我尝试在实时服务器上访问此代码时,它无法正常工作。给出一个异常(exception):

Uncaught exception 'Google_IO_Exception' with message 'Protocol "https" not supported or disabled in libcurl' in /home/legenddude/public_html/newUpload/Google/IO/Curl.php:115 Stack trace: #0 /home/legenddude/public_html/newUpload/Google/IO/Abstract.php(136): Google_IO_Curl->executeRequest(Object(Google_Http_Request)) #1 /home/legenddude/public_html/newUpload/Google/Auth/OAuth2.php(111): Google_IO_Abstract->makeRequest(Object(Google_Http_Request)) #2 /home/legenddude/public_html/newUpload/Google/Client.php(128): Google_Auth_OAuth2->authenticate('4/x7_AOHFKvmlea...', false) #3 /home/legenddude/public_html/newUpload/youtube.php(44): Google_Client->authenticate('4/x7_AOHFKvmlea...') #4 {main} thrown in

这是我的代码 youtube.php-:

<?php
 // Call set_include_path() as needed to point to your client library.
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
set_include_path($_SERVER['DOCUMENT_ROOT'] . '/newUpload/');

require_once 'Google/autoload.php';
require_once 'Google/Client.php';
require_once 'Google/Service/YouTube.php';
session_start();
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
/*
 * You can acquire an OAuth 2.0 client ID and client secret from the
 * {{ Google Cloud Console }} <{{ https://cloud.google.com/console }}>
 * For more information about using OAuth 2.0 to access Google APIs, please see:
 * <https://developers.google.com/youtube/v3/guides/authentication>
 * Please ensure that you have enabled the YouTube Data API for your project.
 */
$OAUTH2_CLIENT_ID = '619899784025-5nn2tqomt3cr6g231qd93nr0lsojdvq9.apps.googleusercontent.com';
$OAUTH2_CLIENT_SECRET = '49K6Ou9PK9n1aamAeg27fnIC';
$REDIRECT = 'http://www.legenddude.com/newUpload/youtube.php';
$APPNAME = "legenddudes";


$client = new Google_Client();
$client->setClientId($OAUTH2_CLIENT_ID);
$client->setClientSecret($OAUTH2_CLIENT_SECRET);
$client->setScopes("https://www.googleapis.com/auth/youtube");
$client->setRedirectUri($REDIRECT);
$client->setApplicationName($APPNAME);
$client->setAccessType('online');
$client->setDeveloperKey('619899784025-5nn2tqomt3cr6g231qd93nr0lsojdvq9@developer.gserviceaccount.com');


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

if (isset($_GET['code'])) {
    if (strval($_SESSION['state']) !== strval($_GET['state'])) {
        die('The session state did not match.');
    }
   //echo $_SESSION['state'];exit;
    $client->authenticate($_GET['code']);
    $_SESSION['token'] = $client->getAccessToken();

}

if (isset($_SESSION['token'])) {
    $client->setAccessToken($_SESSION['token']);
    echo '<code>' . $_SESSION['token'] . '</code>';
}

// Check to ensure that the access token was successfully acquired.
if ($client->getAccessToken()) {
    try {
        // Call the channels.list method to retrieve information about the
        // currently authenticated user's channel.
        $channelsResponse = $youtube->channels->listChannels('contentDetails', array(
            'mine' => 'true',
        ));

        $htmlBody = '';
        foreach ($channelsResponse['items'] as $channel) {
            // Extract the unique playlist ID that identifies the list of videos
            // uploaded to the channel, and then call the playlistItems.list method
            // to retrieve that list.
            $uploadsListId = $channel['contentDetails']['relatedPlaylists']['uploads'];

            $playlistItemsResponse = $youtube->playlistItems->listPlaylistItems('snippet', array(
                'playlistId' => $uploadsListId,
                'maxResults' => 50
            ));

            $htmlBody .= "<h3>Videos in list $uploadsListId</h3><ul>";
            foreach ($playlistItemsResponse['items'] as $playlistItem) {
                $htmlBody .= sprintf('<li>%s (%s)</li>', $playlistItem['snippet']['title'],
                    $playlistItem['snippet']['resourceId']['videoId']);
            }
            $htmlBody .= '</ul>';
        }
    } 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()));
    }

    $_SESSION['token'] = $client->getAccessToken();
} else {
    $state = mt_rand();
    $client->setState($state);
    $_SESSION['state'] = $state;

    $authUrl = $client->createAuthUrl();
    $htmlBody = <<<END
  <h3>Authorization Required</h3>
  <p>You need to <a href="$authUrl">authorise access</a> before proceeding.<p>
END;
}
?>

<!doctype html>
<html>
<head>
    <title>My Uploads</title>
</head>
<body>
<?php echo $htmlBody?>
</body>
</html>`enter code here`

最佳答案

来自 curl_faq :

When passing on a URL to curl to use, it may respond that the particular protocol is not supported or disabled. The particular way this error message is phrased is because curl doesn't make a distinction internally of whether a particular protocol is not supported (i.e. never got any code added that knows how to speak that protocol) or if it was explicitly disabled. curl can be built to only support a given set of protocols, and the rest would then be disabled or not supported.

还有更多:

To get the https:// support into a curl that was previously built but that reports that https:// is not supported, you should dig through the document and logs and check out why the configure script doesn't find the SSL libs and/or include files.

关于php - 带有消息 'Protocol "https 的 Google 服务身份验证 Google_IO_Exception 在 libcurl 中不受支持或禁用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31237942/

相关文章:

php - 了解 Git,使用 php ide 和 ftp

php - Symfony 文本字段的最大长度

php - 将脚本从 PHP mysql_insert_id header 、位置方法转换为 PHP session 方法

list - Mapbox - 如何为属性设置多个值并独立过滤它们

api - Azure API 管理始终返回 404 未找到资源

android - Android 上的 YouTubePlayerFragment 不显示广告 - YouTube Android Player API

java - Android 社​​交网络 Intent

PHP字体高度功能不起作用

c# - 使用 Amazon API for .NET 设置内容编码和内容类型

android - Android上的Flickr和Youtube集成