Adding Multiple Video Responses to a Video Entry


Note that you need to use an authenticated YouTube client object (represented as $ytClient). You can only add responses that are your own videos and they may not show up immediately, depending on whether the owner of the video that you are responding to has enabled automatic acceptance of responses.
// Assuming we have just instantiated a working $httpClient object.
$ytClient = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);

// The video ID that is to receive the responses.
$receiveResponses = 'ABC123';

// A few of your videos that you want to post as responses.
$videoResponses[] = 'defXYZ123';
$videoResponses[] = 'defXYZ124';
$videoResponses[] = 'defXYZ125';

function addVideoResponses($videoResponses, $receiveResponses) {
  global $ytClient;

  $receiveResponsesEntry = $yt->getVideoEntry($receiveResponses);

  foreach ($videoResponses as $videoResponse) {
    $videoResponseEntry = $yt->getVideoEntry($videoResponse);
    $responsesFeedUrl = $receiveResponsesEntry->getVideoResponsesLink()->getHref();

    try {
      $ytClient->insertEntry($videoResponseEntry, $responsesFeedUrl);
    } catch (Zend_Gdata_App_HttpException $httpException) {  
      echo 'ERROR: ' . $httpException->getRawResponseBody();
      
    }
  }
}

addVideoResponses($videoResponses, $receiveResponses);

291 comments:

«Oldest   ‹Older   601 – 291 of 291
«Oldest ‹Older   601 – 291 of 291   Newer› Newest»