Set authenticated user's about me/description/summary - php

I am using the "youtube api" for PHP library, ie zend.
My goal is to set the description, ie what you see when you open the channel of a user in the textbox at the right.
What I did.
function anmelden_yt($name,$passwort)
{
$yt_source = 'sou'; //name of application (can be anything)
$yt_api_key = 'ak';
$yt = null;
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $name,
$password = $passwort,
$service = 'youtube',
$client = null,
$source = $yt_source, // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
return new Zend_Gdata_YouTube($httpClient, $yt_source, NULL, $yt_api_key);
}
$yt = anmelden_yt('name','pw');
$yt->setMajorProtocolVersion(2);
$userProfileEntry = $yt->getUserProfile('name');
$userProfileEntry->setAboutMe('test');
$userProfileEntry->setContent('test');
$userProfileEntry->setSummary('test');
Nothing changed.

Those fields are no longer exposed via the API. They also don't correspond to the channel description display that you're referring to. There currently isn't a way to set that channel description via the API.

Related

Uploading video to an owned youtube channel

I am trying to upload video using my developer key to a youtube channel that is owned by my google account.
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = 'username',
$password = 'pass',
$service = 'youtube',
$client = null,
$source = 'mysource', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$developerKey = 'key';
$applicationId = 'Video Upload';
$clientId = 'Video Uploader v1';
However when i try to upload to that channel it gives me "write-access" error even though this channel is owned by me.
I can manage this youtube channel easily using "switch account" of youtube. but when it comes to upload using the API i get write-access error.
I use upload url like this
http://uploads.gdata.youtube.com/feeds/api/users/CHANNELUSERNAME/uploads
Any idea how to fix this ?
This blog will give you the right information on how to manage multiple channels via API.

Get Youtube video by tags from specific user

I'm trying to get a youtube video from the $username with $tags:
$tags='detskij-sad-198';
require_once('Zend/Loader.php');
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Gdata_ClientLogin');
$authenticationURL = 'https://www.google.com/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = 'Schoolkharkovua',
$password = '*****',
$service = 'youtube',
$client = null,
$source = '*****',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$devkey = '*****';
$yt = new Zend_Gdata_YouTube($httpClient, '', '', $devkey);
$yt->setMajorProtocolVersion(2);
$query = $yt->newVideoQuery();
$query->setMaxResults(4);
$query->setVideoQuery($tags); // also i tried $query->category = $tags;
$query->setAuthor($username);
$videoFeed = $yt->getVideoFeed($query->getQueryUrl(2));
$videoFeed returns no entry, although I know that the $username has a video with $tags and this code to work until mid-March
If I do query only by the $username or by $tags - I get the result.
What am I doing wrong?
PS. http://gdata.youtube.com/demo/index.html return empty video feed too if I trying query by "Keywords" and "Author name" simultaneously
Hhhhhmmmmm.... It seems that "google" no longer get the symbols "-" in tags
But
echo 'Tags: ' . implode(", ", $videoEntry->getVideoTags());
still emty, youtube api don't return video tags!
Guys help me get video tags from my video channel, please!
You need to authenticate your connection, YT returns an empty media$keywords object now (as of last Aug).
https://developers.google.com/youtube/2.0/developers_guide_php#Authentication
and here's their blog post about it...
http://apiblog.youtube.com/2012/08/video-tags-just-for-uploaders.html

Youtube video upload API issue

I just can't seem to get this API working. My eyes are missing the mistakes I'm making. The problem I have is that the page still Shows BLANK.
I need the form to upload the data onto Youtube which will later be displayed on my website.
Here is my code:
<?php
require_once 'library/Zend/Loader/AutoloaderFactory.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');
// start a new session
session_start();
function getAuthSubRequestUrl()
{
$next = 'http://www.example.com/welcome.php';
$scope = 'http://gdata.youtube.com';
$secure = false;
$session = true;
return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session);
}
function getAuthSubHttpClient()
{
if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
echo 'Login!';
return;
} else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
$_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
}
$httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
return $httpClient;
}
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = 'myuser#gmail.com',
$password = 'mypassword',
$service = 'youtube',
$client = null,
$source = 'MySource', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$developerKey = 'ABC123 ... ';
$applicationId = 'Video uploader v1';
$clientId = 'My video upload client - v1';
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
// Assuming that $yt is a valid Zend_Gdata_YouTube object
$yt->setMajorProtocolVersion(2);
function getAndPrintVideoFeed($location = Zend_Gdata_YouTube::VIDEO_URI)
{
$yt = new Zend_Gdata_YouTube();
// set the version to 2 to receive a version 2 feed of entries
$yt->setMajorProtocolVersion(2);
$videoFeed = $yt->getVideoFeed($location);
printVideoFeed($videoFeed);
}
function printVideoFeed($videoFeed)
{
$count = 1;
foreach ($videoFeed as $videoEntry) {
echo "Entry # " . $count . "\n";
printVideoEntry($videoEntry);
echo "\n";
$count++;
}
}
// 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();
$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');
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
// place to redirect user after upload
$nextUrl = 'http://www.example.com/youtube_uploads';
// build the form
$form = '<form action="'. $postUrl .'?nexturl='. $nextUrl .
'" method="post" enctype="multipart/form-data">'.
'<input name="file" type="file"/>'.
'<input name="token" type="hidden" value="'. $tokenValue .'"/>'.
'<input value="Upload Video File" type="submit" />'.
'</form>';
echo "aaaa".$form;
?>
Here is my code with Zend
//include Zend Gdata Libs
require_once("Zend/Gdata/ClientLogin.php");
require_once("Zend/Gdata/HttpClient.php");
require_once("Zend/Gdata/YouTube.php");
require_once("Zend/Gdata/App/HttpException.php");
require_once('Zend/Uri/Http.php');
//yt account info
$yt_user = 'myuser#gmail.com'; //youtube username or gmail account
$yt_pw = 'mypassword'; //account password
$yt_source = 'title of my video'; //name of application (can be anything)
//yt dev key get here : https://code.google.com/apis/youtube/dashboard/
$yt_api_key = ''ABC123 ... ''; //your youtube developer key
//login in to YT
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $yt_user,
$password = $yt_pw,
$service = 'youtube',
$client = null,
$source = $yt_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);
$yt = new Zend_Gdata_YouTube($httpClient, $yt_source, NULL, $yt_api_key);
I can Upload my file and after a while I'm redirected to "$nextUrl".
My issue is that I get this page : http://www.example.com/youtube_uploads?statu=400&error=failed
And I don't no why.
Any Idea, please ?

Uploading video to youtube using api's through php

$httpClient =
Zend_Gdata_ClientLogin::getHttpClient(
$username = '****#gmail.com',
$password = '*****',
$service = 'youtube',
$client = null,
$source = 'testphp',
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
I have got the above code from code.google.com. I want to know what authenticationURL should be. I new to this help me out
If you copied your code from here, then you missed this line:
$authenticationURL= 'https://www.google.com/accounts/ClientLogin';
That's what it is.

CodeIgniter: Upload Video to YouTube

I'm using CodeIgniter + Zend libraries. I want to let users upload videos to my site, which I will then upload to my YouTube channel. This is my first exposure to the YouTube API. Can someone point me in the right direction?
Am I right to be looking at this: http://code.google.com/apis/youtube/2.0/developers_guide_protocol.html#Direct_uploading? Does anyone have a snippet of code that shows how uploading is done via PHP?
Try this its working
class Addvideo extends Controller {
function Addvideo()
{
parent::Controller();
$this->load->library("zend");
$this->zend->load("Zend/Gdata/AuthSub");
$this->zend->load("Zend/Gdata/ClientLogin");
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
/************Authentication**************/
$this->zend->load("Zend/Gdata/YouTube");
$this->zend->load("Zend/Gdata/HttpClient");
$this->zend->load("Zend/Gdata/App/MediaFileSource");
$this->zend->load("Zend/Gdata/App/HttpException");
$this->zend->load("Zend/Uri/Http");
$youtube = new Zend_Gdata_YouTube();
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$Gdata_AuthSub=new Zend_Gdata_AuthSub();
$this->load->helper("text");
}
function index(){
$data['result']='videos';
$this->load->view('videos/newform', $data);
}
function indexed(){
$title = 'GruppoDSE Video';
$description = 'Description';
$youtube = new Zend_Gdata_YouTube();
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $this->config->item('username'),
$password = $this->config->item('password'),
$service = 'youtube',
$client = null,
$source = 'Arts Connector', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$developerKey = $this->config->item('developer_key');
$applicationId = 'Arts Connector';
$clientId = 'My video upload client - v1';
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
// create a new VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle($title);
$myVideoEntry->setVideoDescription($description);
// 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');
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$data['tokenValue'] = $tokenArray['token'];
$data['postUrl'] = $tokenArray['url'];
// place to redirect user after upload
$data['nextUrl'] = 'http://www.avantajsoftwares.com/gruppo/uploadVideo';
$res="Il file video aggiungere con successo, il risultato atteso verrĂ  visualizzato dopo alcune volte";
$this->session->set_userdata('greenFlag',$res);
// build the form
$this->load->view('videos/form', $data);
}
function AddVideoAjax(){
$title=$_POST['title'];
$description=$_POST['description'];
$youtube = new Zend_Gdata_YouTube();
$authenticationURL= 'https://www.google.com/youtube/accounts/ClientLogin';
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = $this->config->item('username'),
$password = $this->config->item('password'),
$service = 'youtube',
$client = null,
$source = 'Arts Connector', // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);
$developerKey = $this->config->item('developer_key');
$applicationId = 'Arts Connector';
$clientId = 'My video upload client - v1';
try {
$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
// create a new VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();
$myVideoEntry->setVideoTitle($title);
$myVideoEntry->setVideoDescription($description);
// The category must be a valid YouTube category!
$myVideoEntry->setVideoCategory('Education');
// Set keywords. Please note that this must be a comma-separated string
// and that individual keywords cannot contain whitespace
$myVideoEntry->SetVideoTags('Seminar, Events');
$tokenHandlerUrl = 'http://gdata.youtube.com/action/GetUploadToken';
$tokenArray = $yt->getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray['token'];
$postUrl = $tokenArray['url'];
// place to redirect user after upload
$nextUrl = 'http://www.avantajsoftwares.com/gruppo/Addvideo';
$res="Il file video aggiungere con successo, il risultato atteso verrĂ  visualizzato dopo alcune volte";
$this->session->set_userdata('greenFlag',$res);
// build the form
echo $form = '<form action="'. $postUrl .'?nexturl='. $nextUrl .
'" method="post" enctype="multipart/form-data" onsubmit="return valid()">'.
'<div style="float:left;"><input name="file" type="file" id="file"/></div><div class="preloader"></div>'.
'<input name="token" type="hidden" value="'. $tokenValue .'"/>'.
'<div style="clear:both"></div>'.
'<div class="login-footer" id="prog_bar style="cursor:pointer"><input value="Carica video" type="submit" id="validate" class="button" onclick="progress_bar()"/></div>'.
'</form>';
} catch (Zend_Gdata_App_Exception $e) {
echo $return="<div class='login-footer' style='width:130px;'><a style='height:16px; padding-top:7px;' class='button' href=".site_url()."Addvideo>Riprova di nuovo</a></div>";
}
// Assuming that $videoEntry is the object that was returned during the upload
//$state = $myVideoEntry->getVideoState();
}
function getAuthSubRequestUrl()
{
$gdata_AuthSub = new Zend_Gdata_AuthSub();
$next = 'http://www.avantajsoftwares.com/gruppo/videos';
$scope = 'http://gdata.youtube.com';
$secure = false;
$session = true;
return $data=$gdata_AuthSub->getAuthSubTokenUri($next, $scope, $secure, $session);
}
function getAuthSubHttpClient()
{
echo $_SESSION['sessionToken'];
if (!isset($_SESSION['sessionToken']) && !isset($_GET['token']) ){
echo 'Login!';
return;
} else if (!isset($_SESSION['sessionToken']) && isset($_GET['token'])) {
$_SESSION['sessionToken'] = Zend_Gdata_AuthSub::getAuthSubSessionToken($_GET['token']);
}
$httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']);
return $httpClient;
}
/*************************** Class end ***********************************/
}
I don't recommend using Zend with CI due to it's size and complexity. I developed a library specifically for CodeIgniter https://github.com/jimdoescode/CodeIgniter-YouTube-API-Library
The library provides several different options for uploading to YouTube. You can do a direct upload where you upload a video stored on your server to youtube. There is also an option to use a form to upload a video from the client to youtube. Check it out and let me know if you have any questions.
The docs have this, as well as other methods, covered for Zend Gdata: Uploading Videos

Categories