Youtube api 谷歌YouTube API v3::服务器到服务器上传服务

Youtube api 谷歌YouTube API v3::服务器到服务器上传服务,youtube-api,google-api,oauth-2.0,google-api-php-client,Youtube Api,Google Api,Oauth 2.0,Google Api Php Client,我们的项目允许用户在登录到我们的会话时将视频上传到我们的公共youtube频道。我们不想要求额外的OAuth2验证,而是遵循GoogleAPIv2 下面是我的代码(php)和错误,但我的一般问题是:我的服务器是否可以使用我的API密钥/机密进行插入视频帖子,而不需要用户进行身份验证。 这个问题很相似。然而,如果用谷歌搜索访问令牌是唯一的答案,我会失望的。谢谢你 谷歌API V3设置: Client ID: xxxx.apps.googleusercontent.com Email addres

我们的项目允许用户在登录到我们的会话时将视频上传到我们的公共youtube频道。我们不想要求额外的OAuth2验证,而是遵循GoogleAPIv2

下面是我的代码(php)和错误,但我的一般问题是:我的服务器是否可以使用我的API密钥/机密进行插入视频帖子,而不需要用户进行身份验证。

这个问题很相似。然而,如果用谷歌搜索访问令牌是唯一的答案,我会失望的。谢谢你

谷歌API V3设置:

Client ID:  xxxx.apps.googleusercontent.com
Email address:  xxxx@developer.gserviceaccount.com
Client secret:  xxxx
Redirect URIs:  http://fbtabs.imagendigital.co/unilever/sedal/surprise/galeria
JavaScript origins: https://fbtabs.imagendigital.co
API key:    
AIzaSyBgS-jMJQUPIiAyX20xC-encFWTPsR7qxQ
Referers:   
Any referer allowed
Activated on:   Jul 4, 2013 1:21 PM
Activated by:    xxxx@gmail.com – you
Notice: Undefined index: content-type in C:\DATA\IDInteractive\SedalSurprise\app\vendor\google-api-php-client\src\service\Google_MediaFileUpload.php on line 99
Caught Google service Exception 401 message is Error calling POST https://www.googleapis.com/upload/youtube/v3/videos?part=player&uploadType=multipart&key=AIzaSyBgS-jMJQUPIiAyX20xC-encFWTPsR7qxQ: (401) Login Required 
Stack trace is #0 C:\DATA\IDInteractive\SedalSurprise\app\vendor\google-api-php-client\src\io\Google_REST.php(36): Google_REST::decodeHttpResponse(Object(Google_HttpRequest)) #1 C:\DATA\IDInteractive\SedalSurprise\app\vendor\google-api-php-client\src\service\Google_ServiceResource.php(186): Google_REST::execute(Object(Google_HttpRequest)) #2 C:\DATA\IDInteractive\SedalSurprise\app\vendor\google-api-php-client\src\contrib\Google_YouTubeService.php(789): Google_ServiceResource->__call('insert', Array) #3 C:\DATA\IDInteractive\SedalSurprise\youtuber.php(56): Google_VideosServiceResource->insert('player', Object(Google_Video), Array) #4 {main}
代码:

<?php
require_once BASE_CD . 'app/src/Idframework/Tools.php';
require_once BASE_CD . 'app/vendor/google-api-php-client/src/Google_Client.php';
require_once BASE_CD . 'app/vendor/google-api-php-client/src/contrib/Google_YouTubeService.php';
$client = new Google_Client();
$client->setApplicationName('Google+ PHP Starter Application');
$client->setClientId('xxx.apps.googleusercontent.com');
$client->setClientSecret('xxxx');
$client->setRedirectUri('http://fbtabs.imagendigital.co/unilever/sedal/surprise/galeria');
$client->setDeveloperKey('xxxx');
$youtube = new Google_YoutubeService($client);
$snippet = new Google_VideoSnippet();
$status = new Google_VideoStatus();
$video = new Google_Video();

if (isset($_POST['tip_desc'])) $snippet->setDescription($_POST['tip_desc']);
    $snippet->setTitle($_POST['tip_name']);
    $snippet->setTags(array("sedal","hair","pello","cabello"));
    $status->privacyStatus = "public";

    $video->setSnippet($snippet);
    $video->setStatus($status);

    $filename = $_FILES['videoInp']['tmp_name'];
    $mime = \Idframework\Tools::get_mime($filename);

    try {
        $part = "status";
        $obj = $youtube->videos->insert($part, $video,
                                         array("data"=>file_get_contents($filename), 
                                        "mimeType" => $mime));
    } catch(Google_ServiceException $e) {
        print "Caught Google service Exception ".$e->getCode(). " message is ".$e->getMessage(). " <br>";
        print "Stack trace is ".$e->getTraceAsString();
    }

首先,不建议让任意用户将视频上传到“主”YouTube频道,原因如下所述

也就是说,如果您决定这么做,那么您需要在每个上传请求中包含一个与您的频道相关联的访问令牌。获取新的访问令牌(一小时后到期)的适当方法是获取以前生成并存储在某处的刷新令牌,并向相应的URL发出HTTP请求以获取访问令牌,如中所述。这是没有办法的——我不确定Google API PHP客户端库中是否有一个本机方法可以为您自动化该过程,但这正是需要在幕后实现的


中的信息似乎确实相关。

我解决了它,我的答案是:享受!