【发布时间】:2013-04-12 01:38:31
【问题描述】:
我一直在尝试通过直接上传将视频上传到 YouTube API。我终于破解了 OAuth 流程并且我有一个有效的令牌。我真的只需要在 YouTube 上做两件事,验证和上传。我没有浏览或使用任何其他功能。用户将视频上传到本网站,我将其发送到 YouTube 进行播放。
我觉得自己已经完成了 80-90% 的路,所以我不想放弃它并使用 Google 提供的 Zend 库。
问题: 当我发送请求时,我得到了这个响应:
HTTP/1.1 413 Request Entity Too Large
Content-Type: text/html; charset=UTF-8
Content-Length: 171
Date: Thu, 18 Apr 2013 18:33:22 GMT
Expires: Thu, 18 Apr 2013 18:33:22 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Connection: close
如果我打开警告,我还会收到 Broken Pipe 警告,这可能只是尝试通过关闭/拒绝连接上传数据的代码。
我的要求是这样的:
POST /feeds/api/users/default/uploads HTTP/1.1
Host: gdata.youtube.com Connection: close
User-Agent: PHP Accept-encoding: identity
Authorization: Bearer <TOKEN IS HERE>
GData-Version: 2.0
X-GData-Key: key=<MYKEYISHERE>
Slug: throwing_can.mp4
Content-Type: multipart/related; boundary="5170429d1b193"
Content-Length: 3920610
文件本身被分块并写入流。
function ytapi_write_file($handle, $path, $chunksize = 8192){
$filehandle = fopen($path, 'r');
while(!feof($filehandle)){
fwrite($handle, fread($filehandle, $chunksize));
}
fclose($filehandle);
$filehandle = null;
}
function ytapi_write($handle, $request){
fwrite($handle, $request);
return $request;
}
像这样。
ytapi_write($handle, $start); //This writes the header.
ytapi_write_file($handle, $path, 8192); //This writes the file raw/binary.
ytapi_write($handle, $end); //This writes the final boundary.
另外,我将它用于标题信息:
$_header = array(
'Host'=>'gdata.youtube.com',
'Connection'=>'close',
'User-Agent'=>'PHP',
'Accept-encoding'=>'identity'
);
知道我做错了什么吗?如果需要,我可以提供更多信息。我上传的文件略大于 3MB,该文件位于相关服务器上。我已验证位置正确。
更新
更改为 uploads.gdata.youtube.com
现在我收到此错误消息:
Host: uploads.gdata.youtube.com
Connection: close
User-Agent: PHP
Accept-encoding: identity
tcp://uploads.gdata.youtube.com:80HTTP/1.1 400 Bad Request
Server: HTTP Upload Server Built on Apr 8 2013 13:06:58 (1365451618)
X-GData-User-Country: US
Content-Type: application/vnd.google.gdata.error+xml
X-GUploader-UploadID: <SOME ID>
Date: Thu, 18 Apr 2013 19:42:14 GMT
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Cache-Control: no-cache, no-store, must-revalidate
Content-Length: 228
Connection: close
【问题讨论】:
-
更改为 uploads.gdata.youtube.com
-
我觉得应该有'https'
-
你不能使用我的例子中的 CURL 吗?您不需要处理“内容长度”和文件块。
-
我现在正在尝试实现它。
-
服务器正在发回一个 XML 格式的实体。该 XML 实际说明了什么错误消息?
标签: php sockets upload youtube-api