我找不到我的"此操作所需的开发人员密钥的解决方案"问题
这是我的代码:
require_once 'Zend/Loader.php'; // the Zend dir must be in your include_path
Zend_Loader::loadClass('Zend_Gdata_YouTube');
$yt = new Zend_Gdata_YouTube();
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = '************@gmail.com',
$password = '************',
$service = 'youtube',
$client = null,
$source = '************', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
// Note that this example creates an unversioned service object.
// You do not need to specify a version number to upload content
// since the upload behavior is the same for all API versions.
$yt = new Zend_Gdata_YouTube($httpClient);
// create a new VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
// create a new Zend_Gdata_App_MediaFileSource object
$filesource = $yt->newMediaFileSource('asd.avi');
$filesource->setContentType('video/x-ms-wmv');
// set slug header
$filesource->setSlug('asd.avi');
// add the filesource to the video entry
$myVideoEntry->setMediaSource($filesource);
$myVideoEntry->setVideoTitle('My Test Movie');
$myVideoEntry->setVideoDescription('My Test Movie');
// The category must be a valid YouTube category!
$myVideoEntry->setVideoCategory('Autos');
// Set keywords. Please note that this must be a comma-separated string
// and that individual keywords cannot contain whitespace
$myVideoEntry->SetVideoTags('cars, funny');
// set some developer tags -- this is optional
// (see Searching by Developer Tags for more details)
$myVideoEntry->setVideoDeveloperTags(array('mydevtag', 'anotherdevtag'));
// set the video's location -- this is also optional
$yt->registerPackage('Zend_Gdata_Geo');
$yt->registerPackage('Zend_Gdata_Geo_Extension');
$where = $yt->newGeoRssWhere();
$position = $yt->newGmlPos('37.0 -122.0');
$where->point = $yt->newGmlPoint($position);
$myVideoEntry->setWhere($where);
// upload URI for the currently authenticated user
$uploadUrl = 'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads';
// try to upload the video, catching a Zend_Gdata_App_HttpException,
// if available, or just a regular Zend_Gdata_App_Exception otherwise
try {
$newEntry = $yt->insertEntry($myVideoEntry, $uploadUrl, 'Zend_Gdata_YouTube_VideoEntry');
} catch (Zend_Gdata_App_HttpException $httpException) {
echo $httpException->getRawResponseBody();
} catch (Zend_Gdata_App_Exception $e) {
echo $e->getMessage();
}
我尝试使用我的devkey以下行,但我需要把它放在哪里?
$developerKey = 'ABC123 ... ';
$applicationId = 'Video uploader v1';
$clientId = 'My video upload client - v1';
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
我试图找到一个完整的PHP代码上传视频到youtube,但没有找到任何东西........
答案 0 :(得分:3)
而不是
$yt = new Zend_Gdata_YouTube($httpClient);
您需要执行以下操作:
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
请注意,$ applicationId和$ clientId必须都是有效的ID。除非已经可用,否则您可以在此处创建应用程序和客户端ID:https://code.google.com/apis/console/
您可以在此处注册https://code.google.com/apis/youtube/dashboard/gwt/index.html#settings
来获取开发人员密钥答案 1 :(得分:2)
可以通过在Google YouTube API中创建产品来获取开发者密钥。
登录您的Google Account:
如果是您的第一次,它会自动将您重定向到创建开发者个人资料:
创建开发者资料后,继续创建产品,它可能就是您想要的一切。
创建产品后,您将获得审查文本框中的开发人员密钥("此处的开发人员密钥")
将其复制到您的代码中,如果您使用的是API的第3版,则可以在那里获得客户端密钥。
要获取客户端ID,您需要在Google API控制台中创建API项目。
登录后您将看到此页面!按create project并创建项目:
它会自动为您创建项目,现在您需要选择要使用的服务。如果您要使用YouTube,请选择YouTube Data API。
现在您可以访问API Access选项卡了。在那里创建一个OAuth ID。
输入您的产品信息:
选择其类型:
获取您的客户ID! :d