Php 如何将AWS S3文件上载到YouTube API

Php 如何将AWS S3文件上载到YouTube API,php,json,amazon-s3,google-api,youtube-data-api,Php,Json,Amazon S3,Google Api,Youtube Data Api,这是一个困难的问题。。。我已经很容易地适应了AWS API,但是谷歌的Oauth2在我的代码中不起作用。。。我尝试过改编StackOverflow和其他来源的代码。。。我尝试了YouTube上传代码生成器,但上传失败。我尝试过其他可用的代码(较旧的Youtube数据API(Google^2.0)…我最大的问题是,一些代码示例不包括API版本,其中类中的错误无法识别…其他代码显然无法工作…这是我的圣杯…请提出建议 <?php require_once '../aws/aws-auto

这是一个困难的问题。。。我已经很容易地适应了AWS API,但是谷歌的Oauth2在我的代码中不起作用。。。我尝试过改编StackOverflow和其他来源的代码。。。我尝试了YouTube上传代码生成器,但上传失败。我尝试过其他可用的代码(较旧的Youtube数据API(Google^2.0)…我最大的问题是,一些代码示例不包括API版本,其中类中的错误无法识别…其他代码显然无法工作…这是我的圣杯…请提出建议

<?php
    require_once '../aws/aws-autoloader.php';
    require_once 'vendor/autoload.php';

    use Aws\S3\S3Client;

    $chunkSizeBytes = 2 * 1024 * 1024; // 2 mb
    $streamName = 's3://gb-football-tribunal-live/1616710690-605d0c226862f-1-0.mp4';

    $s3client = S3Client::factory(array(
        'version' => 'latest',
        'key'     => 'MyS3Key',
        'secret'  => 'MyS3Secret',
        'region'  => 'eu-west-1' // if you need to set.
    ));
    $s3client->registerStreamWrapper();


    $client = new Google_Client();
    $client->setApplicationName('cGbYt');
    $client->setAuthConfig('client_secret.json');
    $client->setAccessType('offline');
    $client->setScopes([
        'https://www.googleapis.com/auth/youtube.upload',
    ]);

    // Define service object for making API requests.
    $service = new Google_Service_YouTube($client);

    // Define the $video object, which will be uploaded as the request body.
    $video = new Google_Service_YouTube_Video();

    // Add 'snippet' object to the $video object.
    $videoSnippet = new Google_Service_YouTube_VideoSnippet();
    $videoSnippet->setCategoryId('17');
    $videoSnippet->setChannelId('UCC7fqHtOns6DtnR7QcaJMaw');
    $videoSnippet->setDescription('Testing of Test00001');
    $videoSnippet->setTags(['Football', 'Test']);
    $videoSnippet->setTitle('Test 00001');
    $video->setSnippet($videoSnippet);

    // Add 'status' object to the $video object.
    $videoStatus = new Google_Service_YouTube_VideoStatus();
    $videoStatus->setEmbeddable(true);
    $videoStatus->setLicense('youtube');
    $videoStatus->setPrivacyStatus('public');
    $videoStatus->setUploadStatus('uploaded');
    $video->setStatus($videoStatus);

    $queryParams = [
        'autoLevels' => false,
        'notifySubscribers' => true,
        'onBehalfOfContentOwner' => 'MyYoutTubeUserID',
        'onBehalfOfContentOwnerChannel' => 'MyYouTubeChannelID',
        'stabilize' => false,
        'uploadType' => 'resumable',
        'alt' => 'json',
        'fields' => 'items(snippet(id))',
    ];

    $response = $service->videos->insert(
      'snippet,status',
      $video,
      $queryParams,
      array(
        'data' => file_get_contents($s3client),
        'mimeType' => 'application/octet-stream',
        'uploadType' => 'multipart'
      )
    );
    print_r($response);
?>


我建议使用官方。这是已知的有效方法。然后根据您的需要对其进行调整。上面的代码根本不运行任何OAuth 2身份验证/授权流。OAuth流是不可避免的,因为它是获取允许您调用的有效凭据数据所必需的。您的错误到底是什么?