小编lit*_*lab的帖子

无法连接到 www.googleapis.com 端口 443:网络无法访问

我正在使用这个库从 WordPress 网站获取 Youtube 的视频和直播。 https://github.com/google/google-api-php-client

代码在过去一个月工作正常,但突然开始随机出现连接失败错误(十次尝试中有两次失败,其他都正常)

这是我收到错误的代码:

function googleapis_get_live_event_widget(){

    //Youtube Videos and Live Events
    require_once( get_stylesheet_directory() . '/lib/google-api-php-client/src/Google/autoload.php' );
    $GOOGLE_DEVELOPER_KEY = get_field('cce_api_google_developer_key','option');

    $client = new Google_Client();
    $client->setDeveloperKey($GOOGLE_DEVELOPER_KEY);
    $youtube = new Google_Service_YouTube($client);

    try {
        $islive = get_field('cce_live_event','option');

        $opts = array();
        $opts['channelId'] = get_field('cce_api_youtube_channel_id','option');
        if($islive) {
            $opts['eventType'] = 'live';
        }
        $opts['type'] = 'video';
        $opts['maxResults'] = 1;
        $opts['order'] = 'date';


        $live_videos = $youtube->search->listSearch('id,snippet',$opts);

        $data = array();
        $data['live_events'] = $live_videos;
        echo Timber::compile('partials/live_event_widget.twig',$data);

    } catch (Exception $e) {
        $error = array();
        $error['message'] = $e->getMessage(); …
Run Code Online (Sandbox Code Playgroud)

php google-api google-api-php-client youtube-data-api

4
推荐指数
1
解决办法
3万
查看次数