3

我的问题是,我应该使用 YouTube API 来加载我从玻璃录制的视频并作为通知的附件发送到我的服务器吗?或者,是否有一个我应该使用的 mirror-api 调用?

例如,我收到的视频的 URL 如下所示: http ://redirector.googlevideo.com/videoplayback?id=875f7e1335214880&itag=22&source=picasa&cmo=sensitive_content%3Dyes&ip=0.0.0.0&ipbits=0&expire=1384018362&sparams=id ,itag,source,ip,ipbits,expire&signature=AB8FC431423D6C86024A36F170ECF20C6F02223C.3FA395F9092F2EE5D6B14ACF49A4C18725A8846B&key=lh1

我确实检查了这个类似的答案:Displaying Video on Webpage from Google Glass,但不确定是否真的应该使用 YouTube API。如果我应该,有人能指出我应该调查哪些电话的正确方向吗?

谢谢!

快速更新以添加更多上下文,因此如果我录制 10 秒视频并通过自定义联系人卡片分享到我的服务器,我会立即得到以下信息(这是我自己通过错误日志进行的调试输出):

[error] Error Downloading Attachment - HTTP ResponseCode:404
[error] ContentUrl:         
[error] ContentType:        video/mp4
[error] id                  ps:5933350025312253298
[error] IsProcessing:       1

因此,这完全有道理,因为视频仍在处理中。现在,如果我等待几分钟并与我的服务器重新共享视频,我会得到以下信息:

[error] Error Downloading Attachment - HTTP ResponseCode:302
[error] ContentUrl:         http://redirector.googlevideo.com/videoplayback?id=e0d5f76ca1fff29a&itag=22&source=picasa&cmo=sensitive_content%3Dyes&ip=0.0.0.0&ipbits=0&expire=1384058057&sparams=id,itag,source,ip,ipbits,expire&signature=CD41362EC3D3DDCD9EA3A63003B4C1A1F95D52C.BAE1608B827661FD47FC8D68DCBCE32F683A013D&key=lh1
[error] ContentType:        video/mp4
[error] id                  ps:5933350025312253298
[error] IsProcessing:       0

相比之下,图像附件总是有效的,看起来像这样:

[error] Downloading Attachment - HTTP ResponseCode:200
[error] ContentUrl:         https://www.googleapis.com/mirror/v1/timeline/7f13b01d-ee26-4b02-b6c3-7f885a452fc9/attachments/ps:5933353306000857698?alt=media
[error] ContentType:        image/jpeg
[error] id                  ps:5933353306000857698
[error] IsProcessing:       0

这就是问题所在。我想不出一种访问视频数据的方法,部分原因是它是一个重定向(似乎??)需要某种身份验证交换来处理,我不知道使用哪个 API 来帮助我做到这一点.

所以,回到我的问题......是否有一种建议的方式让我处理重定向器 url 以将视频下载到我的服务器,或者,甚至只是将它托管在它所在的位置,但包裹一个 youtube'esque 播放器像 G+ 备份云播放器吗?我的目的是让视频公开可见。

谢谢! 更新:这是我正在使用的代码的要点。我刚开始使用 Glass Team 提供的示例 PHP 快速入门:

https://gist.github.com/ozfarman/6953473

4

2 回答 2

2

使用 Googles Mirror Api Client 检查与时间线项目关联的附件的状态。视频可能需要几分钟才能可用,具体取决于其长度。奇怪的是,如果您从他们的重定向中跟踪 302,您最终会进入一个 Picasa 域,考虑到它是视频,这有点奇怪,但确实表明 Google 正在对您的视频进行一些预处理,然后再将其移交。

此代码是我编写的队列过程的一部分,用于处理与 Google 一起检查时间线项目的处理状态。来自 Google 的回调被插入到我的队列服务器中,并由工作人员拾取,该工作人员每 X 秒主动检查一次状态以确定媒体是否已准备好,如果超过循环次数,它只是重新排队作业以由另一个人接收工人。主动检查而不是在回调中返回非 200 代码是非常有益的,因为 Google 会对其 api 调用进行指数退避,因此对于需要一些时间才能进入正确状态的视频,您最终可能会在回调之间等待很长时间来自谷歌。

公共函数运行($data){ $timeline_item_id = $data['timeline_item_id'];

    try{
        $glassUtils = new Google_Glass_Utilities();
        $mirrorClient = new Google_Glass_MirrorClient();
        $client = $mirrorClient->get_google_api_client();
        $client->setAccessToken($data['credentials']);
        $mirror_service = new Google_MirrorService($client);
        echo "\nTIMELINE ITEM ID: " . $data['timeline_item_id'] . "\n";
        $timeline_item = $mirror_service->timeline->get($timeline_item_id);
        $caption = $timeline_item->getText();
    }catch (Exception $e){
        echo "ERROR";
        echo $e->getMessage();
        return true;
    }

    //Blocker that waits for the item to be in the active state
    //Should be faster than waiting for extra callbacks from Google
    try{
        $checkCount = 1;
        while(true){
            $blnProceed = true;

            echo "Check " . $checkCount . " of " . $this->maxSearchChecks . " for attachments on timeline item " . $timeline_item_id . "\n";

            $attachments = $mirror_service->timeline_attachments->listTimelineAttachments($timeline_item_id);
            foreach ($attachments->getItems() as $attachment) {
                echo "Attachment content type: " . $attachment->getContentType() . "\n";
                //echo "Attachment content URL: " . $attachment->getContentUrl();
                if($attachment->getIsProcessingContent() && $attachment->getContentType() == 'video/mp4'){
                    $blnProceed = false;
                }
            }

            if(!$blnProceed){
                echo "Attachments were not ready\n";
                if($checkCount == $this->maxSearchChecks){
                    echo "Job hit max checks, requeueing\n";
                    $task = new BackgroundTask();
                    $task->addTask('GlassVideoImport', $saveData);
                    $task->submit();
                    GearmanPearManager::$LOG[] = "Success";
                    return true;
                }else{
                    $checkCount += 1;
                    echo "Sleeping for " . $this->sleepSecs . " seconds before recheck\n";
                    sleep($this->sleepSecs);
                }
            }else{
                echo "GOT THE TIMELINE ITEM AND ATTACHMENT IS READY\n\n\n\n";
                //Continue
                break;
            }
        }
    }catch (Exception $e){
        echo "ERROR";
        echo $e->getMessage();
        return true;
    }

    //Got here so now go get the attachment
    try{
        $attachment = $mirror_service->timeline_attachments->get($data['timeline_item_id'], $data['timeline_attachment_id']);
        $attachmentBinary = $this->downloadAttachment($data['timeline_item_id'], $attachment);

        //Do something with the binary of the attachment


        GearmanPearManager::$LOG[] = "Success";
        return true;
    }
    catch( Exception $e ) {
        echo $e->getMessage() . "\n";
        @unlink($fileRes['localFile']);
        GearmanPearManager::$LOG[] = "Failure";
        return true;
    }
}

private function downloadAttachment($itemId, $attachment) {
    $request = new Google_HttpRequest(
    $attachment->getContentUrl(), 'GET', null, null);
    $httpRequest = Google_Client::$io->authenticatedRequest($request);
    if ($httpRequest->getResponseHttpCode() == 200) {
        return $httpRequest->getResponseBody();
    } else {
        return null;
    }
}
于 2013-10-12T09:57:18.217 回答
2

您应该使用 Google API 客户端下载附件 URL,它将为您处理授权和任何重定向。请参阅Timeline.attachments.get文档中提供的示例,无论您使用哪种语言进行编码。

于 2013-10-10T20:55:37.537 回答