使用php客户端库v3将视频上传到youtube

时间:2012-11-01 12:38:36

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

我正在尝试使用客户端库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

我需要提供部分参数

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。

1 个答案:

答案 0 :(得分:1)

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

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

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

Google PHP客户端库的发布可能已过时,因此您需要在https://code.google.com/p/google-api-php-client/

结帐来源