gpt4 book ai didi

php - 使用 Zend 上传到 YouTube - 通过代理

转载 作者:搜寻专家 更新时间:2023-10-31 22:02:58 24 4
gpt4 key购买 nike

我已经使用找到的一些代码(Zend with YouTube API)成功地将视频上传到 YouTube。我对其进行了修改,以便可以通过代理服务器上传,但我遇到了麻烦。我已经评论了我为实现代理支持而添加的行。这是代码:

<?php  
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
Zend_Loader::loadClass('Zend_Http_Client_Exception'); //added for proxy support
Zend_Loader::loadClass('Zend_Http_Client'); //added for proxy support
Zend_Loader::loadClass('Zend_Http_Client_Adapter_Proxy'); //added for proxy support
Zend_Loader::loadClass('Zend_Gdata_App_HttpException'); //added for proxy support

$config = array(
'adapter' => 'Zend_Http_Client_Adapter_Proxy',
'proxy_host' => 'MY_PROXY_IP',
'proxy_port' => 8080,
'proxy_user' => 'USER',
'proxy_pass' => 'PASS'
); //added for proxy support

$proxiedHttpClient = new Zend_Gdata_HttpClient('http://www.google.com/', $config); //added for proxy support
try
{
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = 'YOUTUBE EMAIL ID',
$password = 'YOUTUBE PASSWORD',
$service = 'youtube',
$client = $proxiedHttpClient, //changed from "$client = null"
$source = 'mysource',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
}
catch (Zend_Gdata_App_Exception $e)
{
$arry['data']['flag'] = false;
$arry['data']['msg'] = 'Username or Password Invalid.';
print_r(json_encode($arry));
die();
}
$httpClient->setConfig($config); //added for proxy support
$developerKey='DEVELOPER KEY';
$applicationId = 'not require';
$clientId = 'not require';
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
$fileName = "FILENAME";
$fileType = "video/mp4";
$newEntry = new Zend_Gdata_YouTube_VideoEntry();
$filesource = $yt->newMediaFileSource($fileName);
$filesource->setContentType('video/mp4');
$filesource->setSlug($fileName);
$newEntry->setMediaSource($filesource);
$newEntry->setVideoTitle("VIDEO TITLE");
$newEntry->setVideoDescription("VIDEO DESCRIPTION HERE");
$newEntry->setVideoCategory("VIDEO CATEGORY HERE");
$newEntry->setVideoTags("VIDEO TAGS");
try {
$newEntry = $yt->insertEntry($newEntry, 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads', 'Zend_Gdata_YouTube_VideoEntry');
$state = $newEntry->getVideoState();
if ($state)
{
$videourl = $newEntry->getVideoWatchPageUrl();
$arry['data']['flag'] = true;
$arry['data']['url'] = $videourl;
$arry['data']['msg'] = "Video Uploaded Successfully.";
}
else
{
$arry['data']['flag'] = false;
$arry['data']['msg'] = "Not able to retrieve the video status information yet. " ."Please try again later.\n";
}
}
catch (Zend_Gdata_App_Exception $e) {
$arry['data']['flag'] = false;
$arry['data']['msg'] = $e->getMessage();
}
echo "<pre>";
print_r($arry);
?>

当我从命令行执行 PHP 时,它返回的消息是:

Trying to write but we are connected to the wrong proxy server

我一直在测试的代理绝对有效——事实上,如果我使用损坏的代理,它只会显示“用户名或密码无效”。我只在使用工作代理时收到上面的错误消息。

任何指导或解决方案将不胜感激。

最佳答案

我遇到了同样的问题,我找到了适合我的解决方案。我使用内置的 cURL 适配器而不是代理适配器。

请看下面我的例子...

$config = array( 
'adapter' => 'Zend_Http_Client_Adapter_Curl',
'curloptions' => array(CURLOPT_FOLLOWLOCATION => true, CURLOPT_PROXY => "proxy:port", CURLOPT_PROXYUSERPWD => "username:password")
);

关于php - 使用 Zend 上传到 YouTube - 通过代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24647979/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com