开发者

YouTube PHP API - Getting status of previously uploaded video?

Just started digging into the YouTube PHP API and got the browser-based Zend upload script working. However, I can't find any documentation on how to retrieve the status of the video after it's been uploaded. The main reason I would need this is for error handling - I need to be able to know whether the video was approved by YouTube, since someone could technically upload an image or a file too large. I need to know that the vid was approved so that I know what message to display the end user when they return to the site (ie 'Your video is live' or 'Video upload failed').

The YouTube PHP browser-based upload returns a URL parameter status of 200 even if the format or size is incorrect, which is of course not helpful. Any id开发者_StackOverflow社区eas on how else to get this info from the YT object?

All in all, when a user returns to the site, I want to be able to create a YT object based on their specific video ID, and want to be able to confirm that it was not rejected. I'm using ClientLogin to initiate the YouTube obj:

$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
              $username = 'myuser@gmail.com',
              $password = 'mypassword',
              $service = 'youtube',
              $client = null,
              $source = 'MySource', // a short string identifying your application
              $loginToken = null,
              $loginCaptcha = null,
              $authenticationURL);

Any thoughts?


Whew, finally found the answer to this after searching around and piecing together code for the last few days. After you create the $yt object, use the following to check the status:

$yt->setMajorProtocolVersion(2);
$youtubeEntry = $yt->getVideoEntry('YOUR_YOUTUBE_VID_ID', null, true);

if ($youtubeEntry->getControl()){
    $control = $youtubeEntry->getControl();
    $state = $control->getState()->getName();
}

Echoing out $state displays the string 'failed' if the video was not approved for whatever reason. Otherwise it's empty, which means it was approved and is good to go (Guessing the other state names would be: processing, rejected, failed, restricted, as Mient-jan Stelling suggested above).

Crazy how tough this answer was to put together for first-time YouTube API'ers. Solved! (Pats self on back)


Do you have a CallToken if so its pretty easy.

For this example i use Zend_Gdata_Youtube with Zend AuthSub.

WHen uploading your video you had a CallToken, With this call token you can access the status of the video.

$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
          $username = 'myuser@gmail.com',
          $password = 'mypassword',
          $service = 'youtube',
          $client = null,
          $source = 'MySource', // a short string identifying your application
          $loginToken = null,
          $loginCaptcha = null,
          $authenticationURL);

$youtube = new Zend_Gdata_YouTube( $httpClient, '', NULL, YOUTUBE_DEVELOPER_KEY );

$youtubeEntry = $youtube->getFullVideoEntry( 'ID_OF_YOUTUBE_MOVIE' ); 
// its the 11 digit id all youtube video's have

in $youtubeEntry all your data about the video is present

$state = $youtubeEntry->getVideoState();

if state is null then your video is available else make of state a string like this.

(string) $state->getName();

There are about 4 important state names. ( processing, rejected, failed, restricted)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜