间接修改Google_Service_YouTube_InvideoPromotion的重载元素无效

时间:2014-08-28 12:59:12

标签: php youtube-api

我尝试在youtube频道更新API中将视频类型更改为关联网站,但仅更新自定义文字。我收到了通知错误

try{

$responseChannel['invideoPromotion']['items'][0]['type'] = 'website';
$responseChannel['invideoPromotion']['items'][0]['websiteUrl'] ='http://myassociatewebsite.com/';
$responseChannel['invideoPromotion']['items'][0]['customMessage'] = 'Update tex1';

$updateResponse = $youtube->channels->update('invideoPromotion', $responseChannel);
 }catch (Google_ServiceException $e) {
  $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>',
      htmlspecialchars($e->getMessage()));
}

How to fix that issue please confirm it?

2 个答案:

答案 0 :(得分:0)

以下是更新项目的确切更新代码

$responseChannel['invideoPromotion']['items'][0]['id']['type'] = 'website';
$responseChannel['invideoPromotion']['items'][0]['id']['websiteUrl'] = 'http://yourassiociatewebsiteurl';
$responseChannel['invideoPromotion']['items'][0]['customMessage'] = 'Click here';
$responseChannel['invideoPromotion']['items'][0]['timing']['type']= 'offsetFromStart';
$responseChannel['invideoPromotion']['items'][0]['timing']['offsetMs']= 100;
$responseChannel['invideoPromotion']['items'][0]['timing']['durationMs']= 10000;

答案 1 :(得分:0)

我遇到了与上述相同的问题,这里是我如何设法让它发挥作用:

if( !empty($responseChannel['invideoPromotion']['items']) ){
    // This part did not work for me, that's probably because the channel does not have any InvideoPromotion setup yet
    $responseChannel['invideoPromotion']['items'][0]['id']['type'] = 'video';
    $responseChannel['invideoPromotion']['items'][0]['id']['videoId'] = $video_id;
    $responseChannel['invideoPromotion']['items'][0]['customMessage'] = 'Click here';
    $responseChannel['invideoPromotion']['items'][0]['timing']['type']= 'offsetFromStart';
    $responseChannel['invideoPromotion']['items'][0]['timing']['offsetMs']= 100;
    $responseChannel['invideoPromotion']['items'][0]['timing']['durationMs']= 10000;
}else{
    $invideoPromo = new Google_Service_YouTube_InvideoPromotion();
    $ivP_items[] = array(
        'id' => array(
            'type' => 'video',
            'videoId' => $video_id
         ),
        'timing' => array(
            'type' => 'offsetFromStart',
            'offsetMs' => 100,
            'durationMs' => 10000
        )
    );
    $invideoPromo->setItems($ivP_items);

    $responseChannel['invideoPromotion'] = $invideoPromo;
}

希望有帮助...