Accessing youtube services from php

本秂侑毒 提交于 2019-12-11 07:01:04

问题


I am completely new to php. I am trying to build a system to upload videos to youtube and preserve their URL. Another flash application later combines them. I am clearing the target so that i can be assured that the library can perform these tasks.

1) upload on a default channel 2) get video url 3) download video for offline viewing

I found the zend library which is used with php by googling. But facing a lot problem. I am using WAMP. I copied the zend library folder to "C:\wamp\www\zend" and changed the php.ini here

; Windows: "\path1;\path2" include_path = ".;C:\wamp\www\zend\library;c:\php\includes"

feeling no change. So I am trying to test the library with this code.

<?php 
error_reporting(E_ALL);
ini_set('display_errors', 1);

set_include_path('C:/wamp/library/zend/library' . PATH_SEPARATOR . get_include_path());

require_once 'zend/library/Zend/Gdata/YouTube.php';
require_once 'zend/library/Zend/Gdata/ClientLogin.php';

require_once 'zend/library/Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();

$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = 
  Zend_Gdata_ClientLogin::getHttpClient(
              $username = 'shabab.h.siddique@gmail.com',
              $password = '***',
              $service = 'youtube',
              $client = null,
              $source = 'testphp', 
              $loginToken = null,
              $loginCaptcha = null,
              $authenticationURL);



$developerKey = 'AI3....w';
$applicationId = 'Student Collaborative Video System';
$clientId = 'Student Collaborative Video System';

$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);

$yt->setMajorProtocolVersion(2);


$videoFeed = $yt->getVideoFeed(Zend_Gdata_YouTube::VIDEO_URI);
printVideoFeed($videoFeed);

var_dump($videoFeed);

?>

THe error i currently see is

1 0.0023 375392 {main}( ) ..\testphp.php:0

2 0.0086 560192 require_once( 'C:\wamp\www\zend\library\Zend\Gdata\YouTube.php' ) ..\testphp.php:7


回答1:


Your code worked fine for me, I just had to adjust the include path from \zend\library to X:/zend/framework/library which was where I put it on my PC. Make sure to use the full path to the framework when setting up the include path.

Then I needed to specifically include the Zend_Gdata files we would be using. Here is code that worked.

<?php 
set_include_path('X:/zend/framework/library' . PATH_SEPARATOR . get_include_path());

// we must manually require these since we didn't set up the autoloader
require_once 'Zend/Gdata/YouTube.php';
require_once 'Zend/Gdata/ClientLogin.php';

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

$developerKey = 'myprodkey';
$applicationId = 'TestProduct';
$clientId = 'Student Collaborative Video System';
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
$yt->setMajorProtocolVersion(2);
$videoFeed = $yt->getVideoFeed(Zend_Gdata_YouTube::VIDEO_URI);
//printVideoFeed($videoFeed);

var_dump($videoFeed);  // worked, printed out a list of videos in my app



回答2:


replace

require_once 'Zend\Loader.php';

with

require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();


来源:https://stackoverflow.com/questions/7628677/accessing-youtube-services-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!