使用php向Youtube用户发送消息

时间:2014-10-21 23:26:40

标签: php api youtube

我想通过向他发送包含常用方式链接的消息来验证Youtube用户(通常通过电子邮件完成)。但我无法使用Youtube API(有一些关于它的手册,但它不起作用 - https://developers.google.com/youtube/2.0/developers_guide_php?hl=fr)。任何人都可以帮我吗?感谢。

<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
//set_include_path('C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\ZendGdata-1.12.9\\library');
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();

//phpinfo();
Zend_Loader::loadClass('Zend_Gdata_ClientLogin'); 

$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
                 $username = 'bloggerspace2all@gmail.com',
                 $password = 'paramparam',
                 $service = 'youtube',
                 $client = null,
                 $source = 'Checking_channel', // a short string identifying your application
                 $loginToken = null,
                 $loginCaptcha = null,
                 $authenticationURL);

$myDeveloperKey = 'AI39si6AwkrbzJtbqQtRZVWlgV8mQOmPcmKoi2l_cSwROMfmYJIjwNuk8fF3HAXyKViE7hvIbR_RcpvgZlqMCAlqBlCPRt9xyg';
$httpClient->setHeaders('X-GData-Key', "key=${myDeveloperKey}");
$yt = new Zend_Gdata_YouTube($httpClient);                                          


$newContact = $yt->newContactEntry();
$newContact->username = $yt->newUsername('SOgHL3mGLe0--TEWo5Bz4w');
$newContact->category = array($yt->newCategory('http://gdata.youtube.com/schemas/2007#friend', 
                                               'http://schemas.google.com/g/2005#kind'));



$inboxUrl = 'http://gdata.youtube.com/feeds/api/users/SOgHL3mGLe0--TEWo5Bz4w/inbox';
$videoMessageEntry = $yt->newEntry();

// pass in the ID of the video to be included in your message (required)
$newMessage = $yt->newMediaEntry();
$newMessage->id = $yt->newId('wSq1AewR_Vs');
$newMessage->title = $yt->newTitle('message title');
$newMessage->extensionElements = array($yt->newDescription('message body'));

// insert the message
try {
  $yt->insertEntry($newMessage, $inboxUrl);
} catch (Zend_App_Excetion $e) {
  print $e->getMessage();
}
?> 

显示的错误:

Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 403 Forbidden' in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ZendGdata-1.12.9\library\Zend\Gdata\App.php:717 Stack trace: #0 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ZendGdata-1.12.9\library\Zend\Gdata.php(219): Zend_Gdata_App->performHttpRequest('POST', 'http://gdata.yo...', Array, '<atom:entry xml...', 'application/ato...', NULL) #1 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ZendGdata-1.12.9\library\Zend\Gdata\App.php(908): Zend_Gdata->performHttpRequest('POST', 'http://gdata.yo...', Array, '<atom:entry xml...', 'application/ato...') #2 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ZendGdata-1.12.9\library\Zend\Gdata\App.php(983): Zend_Gdata_App->post(Object(Zend_Gdata_YouTube_MediaEntry), 'http://gdata.yo...', NULL, NULL, Array) #3 C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\temp.php(46): Zend_Gdata_App->insertEntry(Object(Ze in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\ZendGdata-1.12.9\library\Zend\Gdata\App.php on line 717 

0 个答案:

没有答案