我只想向YouTube的服务器发送POST请求,以便通过OAuth将视频直接上传到YouTube。
我有访问令牌和开发人员密钥 - 如何从PHP向YouTube的gdata服务器发送POST请求?
我想发送的POST请求位于:Sending an Upload API Request
POST /feeds/api/users/default/uploads HTTP/1.1
Host: uploads.gdata.youtube.com
Authorization: Bearer ACCESS_TOKEN
GData-Version: 2
X-GData-Key: key=DEVELOPER_KEY
Slug: VIDEO_FILENAME
Content-Type: multipart/related; boundary="BOUNDARY_STRING"
Content-Length: CONTENT_LENGTH
Connection: close
--<boundary_string>
Content-Type: application/atom+xml; charset=UTF-8
API_XML_request
--BOUNDARY_STRING
Content-Type: VIDEO_CONTENT_TYPE
Content-Transfer-Encoding: binary
<Binary File Data>
--BOUNDARY_STRING--
我尝试了以下功能,并且更喜欢它,但是它无法发送上述POST请求的XML部分。
if (!function_exists('send_post_request'))
{
function send_post_request($url, $data)
{
$context = stream_context_create(array('http' => array('method' => 'POST',
'content' => http_build_query($data))));
$result = file_get_contents($url, FALSE, $context);
return $result;
}
}
我也试过cURL!