gpt4 book ai didi

php - YouTube配额用完了,我有什么选择?

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

我正在客户关系部门工作,并且正在创建一个可以回复每个YouTube评论的应用。

因此,我现在要做的基本上是一个从YouTube Data API v3中提取评论数据的脚本。该脚本是一个循环脚本,每30秒就会调用一次,但是您可能知道YouTube API有配额限制,因此我一直坚持下去。

我愿意接受任何解决方案:

  • 我是否必须向YouTube申请更多配额
  • 我应该应用多少配额(基本上,我只是从其他人,从who,id和timestamp提取评论数据)或sis。

  • 我的代码
    <?php



    if (!file_exists(__DIR__ . '/youtube_vendor/autoload.php')) {

    throw new Exception(sprintf('Please run "composer require google/apiclient:~2.0" in "%s"', __DIR__));

    }

    require_once __DIR__ . '/youtube_vendor/autoload.php';

    include "mysql.php";

    $db = new db();

    $client = new Google_Client();

    $client->setAuthConfig('client_secret.json');

    $client->addScope('https://www.googleapis.com/auth/youtube.readonly');

    $client->addScope('https://www.googleapis.com/auth/youtube.force-ssl');



    $client->setRedirectUri('your_url');

    // offline access will give you both an access and refresh token so that

    // your app can refresh the access token without user interaction.

    $client->setAccessType('offline');

    // Using "consent" ensures that your application always receives a refresh token.

    // If you are not using offline access, you can omit this.

    $client->setPrompt("consent");

    $client->setIncludeGrantedScopes(true); // incremental auth

    $auth_url = $client->createAuthUrl();

    if(isset($_GET['code'])) {

    // id index exists

    $client->authenticate($_GET['code']);

    $access_token = $client->getAccessToken();

    // var_dump($access_token);

    // echo "<br><br>";

    // file_put_contents("received.txt",var_dump($access_token));



    // $access_token = file_get_contents("received.txt");

    // // $file = json_decode($fb);

    // var_dump($access_token);

    // serialize your input array (say $array)

    $serializedData = serialize($access_token);



    // save serialized data in a text file

    file_put_contents('youtube_access_token.txt', $serializedData);



    // at a later point, you can convert it back to array like:

    $recoveredData = file_get_contents('youtube_access_token.txt');



    // unserializing to get actual array

    $access_token = unserialize($recoveredData);



    // you can print your array like

    print_r($access_token);

    echo "<br>";

    $client->setAccessToken($access_token);

    $service = new Google_Service_YouTube($client);

    // $channel = $youtube->channels->listChannels('snippet', array('mine' => $mine));

    // var_dump($channel);

    $queryParams = [

    'maxResults' => 25,

    'mine' => true

    ];

    $arrayComment = array();

    $arrayReplies = array();

    $responseVideo = $service->activities->listActivities('snippet,contentDetails', $queryParams);

    foreach($responseVideo['items'] as $video)

    {

    $db->insert_youtube_video($video['snippet']['channelId'],$video['snippet']['channelTitle'],$video['snippet']['publishedAt'],$video['snippet']['title'],$video['snippet']['description'],$video['snippet']['thumbnails']['standard']['url'],$video['contentDetails']['upload']['videoId']);



    $queryParams = [

    'videoId' => $video['contentDetails']['upload']['videoId']

    ];



    $responseComment = $service->commentThreads->listCommentThreads('snippet,replies', $queryParams);

    foreach($responseComment['items'] as $comment)

    {

    $db->insert_youtube_comment($comment['snippet']['topLevelComment']['snippet']['authorChannelUrl'],$comment['snippet']['topLevelComment']['snippet']['authorDisplayName'],$comment['snippet']['topLevelComment']['snippet']['authorProfileImageUrl'],$comment['snippet']['topLevelComment']['snippet']['publishedAt'],$comment['snippet']['topLevelComment']['snippet']['updatedAt'],$comment['snippet']['topLevelComment']['snippet']['textDisplay'],$comment['snippet']['topLevelComment']['snippet']['videoId'],$comment['snippet']['topLevelComment']['id']);

    $queryParams = [

    'parentId' => $comment['snippet']['topLevelComment']['id']

    ];



    $responseReplies = $service->comments->listComments('snippet', $queryParams);

    foreach ($responseReplies['items'] as $replies)

    {

    $db->insert_youtube_replies($replies['snippet']['authorChannelUrl'],$replies['snippet']['authorDisplayName'],$replies['snippet']['authorProfileImageUrl'],$replies['snippet']['publishedAt'],$replies['snippet']['updatedAt'],$replies['snippet']['textDisplay'],$replies['snippet']['videoId'],$comment['snippet']['topLevelComment']['id'],$replies['id']);

    }

    $arrayReplies[] = $responseReplies;

    }

    $arrayComment[] = $responseComment;

    }







    }

    else

    {

    echo $auth_url;

    }



    ?>

    <textarea style="width:100%;height:300px"><?php print_r($responseVideo['items']); ?><?php print_r($arrayComment); ?><?php print_r($arrayReplies); ?></textarea>
    <script>
    setTimeout(function () { window.location.reload(); }, 15*1000);
    document.write(new Date());
    </script>

    最佳答案

    Do I have to apply for more quota to YouTube



    如果您想避免超出配额并继续进行现在要发送的请求数。是的,您需要申请配额扩展。

    我会尽快申请,可能需要很长时间才能获得延期。

    How much quota should i apply ( basically im only pulling comment data, from who, id , and timestamp ) or sis there any other way.



    那取决于你。您每天要发出几个请求。您将需要做一些数学运算然后加以补充,以确保将来可以增加您的应用程序。

    关于php - YouTube配额用完了,我有什么选择?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62446838/

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