Upload video to Youtube using Youtube API V3 and PHP

后端 未结 4 691
自闭症患者
自闭症患者 2020-12-07 14:46

I am trying to upload a video to Youtube using PHP. I am using Youtube API v3 and I am using the latest checked out source code of Google API PHP Client library.
I am us

4条回答
  •  旧时难觅i
    2020-12-07 15:12

    I was able to get the upload working using the following code:

    if($client->getAccessToken()) {
        $snippet = new Google_VideoSnippet();
        $snippet->setTitle("Test title");
        $snippet->setDescription("Test descrition");
        $snippet->setTags(array("tag1","tag2"));
        $snippet->setCategoryId("22");
    
        $status = new Google_VideoStatus();
        $status->privacyStatus = "private";
    
        $video = new Google_Video();
        $video->setSnippet($snippet);
        $video->setStatus($status);
    
        $error = true;
        $i = 0;
    
        try {
            $obj = $youTubeService->videos->insert("status,snippet", $video,
                                             array("data"=>file_get_contents("video.mp4"), 
                                            "mimeType" => "video/mp4"));
        } catch(Google_ServiceException $e) {
            print "Caught Google service Exception ".$e->getCode(). " message is ".$e->getMessage(). " 
    "; print "Stack trace is ".$e->getTraceAsString(); } }

提交回复
热议问题