我想使用ajax请求上传YouTube视频。以下脚本用于创建表单以将视频上传到YouTube:
function createUploadForm($videoTitle, $videoDescription, $videoCategory, $videoTags, $nextUrl = null)
{
$httpClient = getAuthSubHttpClient();
$youTubeService = new Zend_Gdata_YouTube($httpClient);
$newVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$newVideoEntry->setVideoTitle($videoTitle);
$newVideoEntry->setVideoDescription($videoDescription);
//make sure first character in category is capitalized
$videoCategory = strtoupper(substr($videoCategory, 0, 1))
. substr($videoCategory, 1);
$newVideoEntry->setVideoCategory($videoCategory);
// convert videoTags from whitespace separated into comma separated
$videoTagsArray = explode(' ', trim($videoTags));
$newVideoEntry->setVideoTags(implode(', ', $videoTagsArray));
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
try {
$tokenArray = $youTubeService->getFormUploadToken($newVideoEntry, $tokenHandlerUrl);
if (loggingEnabled()) {
logMessage($httpClient->getLastRequest(), 'request');
logMessage($httpClient->getLastResponse()->getBody(), 'response');
}
} catch (Zend_Gdata_App_HttpException $httpException) {
print 'ERROR ' . $httpException->getMessage()
. ' HTTP details<br /><textarea cols="100" rows="20">'
. $httpException->getRawResponseBody()
. '</textarea><br />'
. '<a href="session_details.php">'
. 'click here to view details of last request</a><br />';
return;
} catch (Zend_Gdata_App_Exception $e) {
print 'ERROR - Could not retrieve token for syndicated upload. '
. $e->getMessage()
. '<br /><a href="session_details.php">'
. 'click here to view details of last request</a><br />';
return;
}
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
// place to redirect user after upload
if (!$nextUrl) {
$nextUrl = $_SESSION['homeUrl'];
}
print <<< END
<br /><form id="ajaxform" action="${postUrl}?nexturl=${nextUrl}"
method="post" enctype="multipart/form-data">
<input name="file" type="file"/>
<input name="token" type="hidden" value="${tokenValue}"/>
<input value="Upload Video File" type="submit" />
</form>
END;
}
最后,使用action="${postUrl}?nexturl=${nextUrl}
创建表单,该表单告知YouTube在上传完成后重定向浏览器。当用户被重定向到nextUrl
时,会有两个变量与URL一起传递(上传视频的状态和该视频的ID)。我不想重新加载页面,但似乎nextUrl
是强制性的。此外,我希望能够获得该ID以供进一步使用。
是否可以更改自动重定向的行为并以任何其他方式传递这些值?
由于