【问题标题】:How to redirect after direct upload using youtube api使用youtube api直接上传后如何重定向
【发布时间】:2012-10-31 21:36:46
【问题描述】:

我正在尝试使用 PHP 的 youtube api 将视频从服务器直接上传到 youtube。上传代码在控制器中,如下所示 函数上传视频(){ require_once 'Zend/Loader.php';

    Zend_Loader::loadClass('Zend_Gdata_YouTube');
    $yt = new Zend_Gdata_YouTube();
    Zend_Loader::loadClass('Zend_Gdata_AuthSub');
    Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
    //client login
    $authenticationURL = 'https://www.google.com/accounts/ClientLogin';
    $httpClient = Zend_Gdata_ClientLogin::getHttpClient($username = 'myusername@gmail.com', $password = 'password', $service = 'youtube', $client = null, $source = 'videotest',$loginToken = null, $loginCaptcha = null, $authenticationURL);
    $developerKey = 'my-key';
    $yt = new Zend_Gdata_YouTube($httpClient, "videotest",null,$developerKey);

    $myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

    // create a new Zend_Gdata_App_MediaFileSource object
     $path = Configure::read('Files.write');
     $video = $path . DS . 'videos' . DS .'car.mp4';
    $filesource = $yt -> newMediaFileSource($video);
    $filesource -> setContentType('video/mp4');

    $filesource -> setSlug($video);

    // add the filesource to the video entry
    $myVideoEntry -> setMediaSource($filesource);

    $myVideoEntry -> setVideoTitle('car');
    $myVideoEntry -> setVideoDescription('car video');
    // The category must be a valid YouTube category!
    $myVideoEntry -> setVideoCategory('Autos');


    $myVideoEntry -> SetVideoTags('cars, test');

    $myVideoEntry -> setVideoDeveloperTags(array('mydevtag', 'anotherdevtag'));

    $myVideoEntry->setVideoPrivate();

    // upload URI for the currently authenticated user
    $uploadUrl = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";


    try {
        $newEntry = $yt -> insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
echo "returned from youtube";
$this -> redirect('/videos/view');

    } catch (Zend_Gdata_App_HttpException $httpException) {
        //print_r($httpException);
        echo $httpException -> getRawResponseBody();
    } catch (Zend_Gdata_App_Exception $e) {
        print_r($e);
        echo $e -> getMessage();
    }

}

视频被上传到我的 youtube 频道,但上传后我只看到一个空白屏幕,它没有被重定向。事实上,它在 insertentry 后没有执行任何语句。这里有什么遗漏吗?

【问题讨论】:

  • 表单中 $nextUrl 后面,method="post" 之前缺少一个空格
  • 好的,我现在将其编辑为 $form = "
    ";..但仍然是相同的空白页面并且没有重定向

标签: php zend-framework youtube-api


【解决方案1】:

如果您想通过 HTML 表单提交视频,然后在完成后自动重定向到另一个页面,您应该使用 browser-based upload flow

如果您坚持使用直接上传流程,那么我不确定您的问题的答案是什么,因为它与 YouTube API 没有直接关系。它只是归结为“在进行一些任意 PHP 调用后,我如何重定向到新网页”。

【讨论】:

  • 我在我的 cakephp 控制器中直接上传。上传成功后,我只会看到一个空白屏幕(即) $this -> redirect('/videos/view');不重定向。
  • $yt->insertEntry,不返回。但是视频已上传并且没有抛出异常。我一直很难调试这个。请帮忙!
  • 我不知道 CakePHP 是什么,也不知道为什么它会阻止您进行基于浏览器的上传而不是直接上传。
  • 我不想在用户将视频上传到我的网站后立即将其上传到 youtube。我希望稍后上传视频(在管理员批准后)。所以浏览器上传对我不起作用。
【解决方案2】:

我深入研究了这个问题,发现问题出在 zend/gdata/app.php 的方法 insertentry 中。不知为何

 $returnEntry = new $className($response->getBody());

失败,即使 $response->getBody() 不为空。所以现在,我注释掉了 post() 之后的代码,并从此方法返回 null。它工作正常,控件返回到我的应用程序。我不确定这是一个错误还是缺少某些东西。如果有人能指出发生了什么问题,那就太好了。谢谢。

【讨论】:

    猜你喜欢
    • 2012-08-29
    • 2016-03-30
    • 2014-05-31
    • 1970-01-01
    • 2011-05-24
    • 2014-09-21
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    相关资源
    最近更新 更多