【问题标题】:Upload video to youtube using php client library v3使用 php 客户端库 v3 将视频上传到 youtube
【发布时间】:2012-10-22 01:14:24
【问题描述】:

我正在尝试使用客户端库 v3 将视频上传到 youtube。

v3 库是实验性的,没有太多文档 (提供的样本不包括 youtube)

我已经使用 oauth 2.0 正确验证了用户。当我有访问令牌时,我正在尝试使用此代码。

if ($client->getAccessToken()) {
    $snippet = new Google_VideoSnippet();
    $snippet -> setTitle = "Demo title";
    $snippet -> setDescriptio = "Demo descrition";
    $snippet -> setTags = array("tag1","tag2");
    $snippet -> setMimeType = 'video/quicktime';

    $video = new Google_Video();
    $video -> setSnippet($snippet);

    // Not sure what to do now....

    $_SESSION['access_token'] = $client->getAccessToken();
}

来自docs

我需要提供一个part参数

The part parameter serves two purposes in this operation. It identifies the properties that the write operation will set as well as the properties that the API response will include.

The part names that you can include in the parameter value are snippet, contentDetails, player, statistics, status, and topicDetails. However, not all of those parts contain properties that can be set when setting or updating a video's metadata. For example, the statistics object encapsulates statistics that YouTube calculates for a video and does not contain values that you can set or modify. If the parameter value specifies a part that does not contain mutable values, that part will still be included in the API response.

但是除了我无法理解的 python 示例之外,它缺少文档。 (示例在链接底部,我提供)

请不要给出 zend 库的示例/链接,它使用了我不想要的 auth-sub。 我想使用 oauth 2.0。

【问题讨论】:

    标签: php youtube-api google-api-client google-api-php-client


    【解决方案1】:

    上传视频的代码如下所示。

    $youtubeService->videos->insert($part, Google_Video $postBody, $optParams = array());
    

    'part' 是您希望请求返回的内容。在这种情况下,可能只是 status,它返回有关上传状态的信息。

    Google PHP 客户端库的版本可能较旧,因此您需要在https://code.google.com/p/google-api-php-client/ 处查看源代码

    【讨论】:

    • 哦,我刚刚注意到代码刚刚在 2 天前更新。我刚退房。让我试试,等我测试了再告诉你
    • 有效,我使用的是旧版本(已发布版本),它没有任何insert的方法
    猜你喜欢
    • 2014-02-01
    • 1970-01-01
    • 2012-12-23
    • 2011-11-19
    • 2013-01-27
    • 2015-08-12
    • 2014-11-22
    • 2016-08-22
    • 2014-06-23
    相关资源
    最近更新 更多