dongxing2030 2014-10-21 23:26
浏览 48

使用php向Youtube用户发送消息

I want to verify a Youtube user by sending him a message containing a link in a common way (which is usually done through email). But I haven't been able to do it using the Youtube API (there's some manual about it but it doesn't work - https://developers.google.com/youtube/2.0/developers_guide_php?hl=fr). Can anybody help me with this? Thanks.

<?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();
}
?> 

The error that was displayed:

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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀
    • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
    • ¥15 关于#hadoop#的问题
    • ¥15 (标签-Python|关键词-socket)