문제

I am trying to upload a video to youtube using client library v3.

The v3 library is experimental and does not have much documentation (samples provided does not include youtube)

I have properly authenticated user with oauth 2.0. And when I have access token, I am trying with this code.

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();
}

From the docs,

I need to supply a part parameter

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.

But it lacks documentation except a python example which I am not able to understand. (the example is at the bottom of the link , I provided)

Please, dont give example/links to zend library, it uses auth-sub which I dont want. I want to use oauth 2.0.

도움이 되었습니까?

해결책

The code to upload a video looks like this.

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

'part' is what you want the request to return. In this case that could just be status, which return information about the status of the upload.

The release of the Google PHP client library might be old, so you'll want to checkout the source at https://code.google.com/p/google-api-php-client/

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top