【问题标题】:Developer key required for this operation此操作需要开发者密钥
【发布时间】:2013-04-02 20:08:41
【问题描述】:

我没有找到“此操作所需的开发者密钥”问题的解决方案。

这是我的代码:

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,但没有找到任何东西............

【问题讨论】:

    标签: php youtube-api


    【解决方案1】:

    代替

    $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

    【讨论】:

    • 感谢您的帮助,辛苦了!
    【解决方案2】:

    如何获取开发者密钥

    开发者密钥可以通过在 Google YouTube API 中创建产品来获得。

    登录您的Google Account:

    如果您是第一次,它会自动将您重定向到创建开发者资料:

    创建您的开发者资料后,继续创建产品,它可能是您想要的一切。

    创建产品后,您将在审查的文本框中获得开发者密钥(“此处为开发者密钥”)

    将其复制到您的代码中,如果您使用的是 API 版本 3,则可以在此处获取客户端密钥。

    如何获取客户 ID

    为了获取客户端 ID,您需要在 Google API 的控制台中创建一个 API 项目。

    Google API's Console

    登录后你会看到这个页面!按创建项目并创建您的项目:

    它会自动为您创建项目,现在您需要选择要使用的服务。如果您要使用 YouTube,请选择 YouTube 数据 API。

    现在您将能够进入 API 访问选项卡。在那里创建一个 OAuth ID。

    输入您的产品信息:

    选择它的类型:

    获取您的客户 ID! :D

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-30
    • 1970-01-01
    • 2019-09-29
    • 1970-01-01
    • 2013-12-27
    • 1970-01-01
    • 2012-07-29
    • 1970-01-01
    相关资源
    最近更新 更多