Youtube Data API v3 - 配额使用问题

时间:2017-03-23 17:45:56

标签: youtube-api quota youtube-data-api

在我的应用程序中,我想使用基于用户的配额(请求/秒/用户)。我随机发送(用于测试查询) quotaUser 以及我的所有请求。但是,在控制台中,我看到配额的总体使用量增加(project console view)。传输 quotaUser 参数不会影响任何内容。也许我没有正确理解配额使用的文档。是否有可能每天从多个应用程序用户执行超过1,000,000个请求?

这是我的代码:

    $client = new Google_Client();
    $client->setAuthConfigFile(SITE_PATH . '/vendor/access_data.json');
    $client->setScopes('https://www.googleapis.com/auth/youtube');
    $client->setAccessType('offline');
    $client->setApprovalPrompt('force');
    $redirect = filter_var('http://' . $_SERVER['HTTP_HOST'] . '/test', FILTER_SANITIZE_URL);
    $client->setRedirectUri($redirect);
    $youtube = new Google_Service_YouTube($client);

    if (isset($_GET['code']))
    {
        $userId = rand(1000, 100000);
        $client->authenticate($_GET['code']);
        $token = $client->getAccessToken();
        $client->setAccessToken($token);

        $channelsResponse = $youtube->channels->listChannels('snippet,contentDetails,statistics,status,brandingSettings', array(
            'mine' => 'true',
            'quotaUser' => $userId
        ));

        $videoResponse = $youtube->playlistItems->listPlaylistItems('snippet', array(
            'playlistId' => $channelsResponse['items'][0]['contentDetails']['relatedPlaylists']['uploads'],
            'maxResults'=> '50',
            'quotaUser' => $userId
        ));
        $videos = [];
        foreach($videoResponse['items'] as $video)
        {
            $videos[] = $video['snippet']['resourceId']['videoId'];
        }
        while(isset($videoResponse['nextPageToken']))
        {
            $videoResponse = $youtube->playlistItems->listPlaylistItems('snippet', array(
                'playlistId' => $channelsResponse['items'][0]['contentDetails']['relatedPlaylists']['uploads'],
                'maxResults'=> '50',
                'pageToken' => $videoResponse['nextPageToken']
            ));
            foreach($videoResponse['items'] as $video)
            {
                $videos[] = $video['snippet']['resourceId']['videoId'];
            }
        }

        print_r($videos);
    }

0 个答案:

没有答案