<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>yalamber.com &#187; api</title>
	<atom:link href="http://blog.yalamber.com/category/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.yalamber.com</link>
	<description>About me, my learnings and more..</description>
	<lastBuildDate>Thu, 02 Sep 2010 16:29:15 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>using youtube api to upload videos from your site</title>
		<link>http://blog.yalamber.com/2009/04/15/using-youtube-api-to-upload-videos-from-your-site/</link>
		<comments>http://blog.yalamber.com/2009/04/15/using-youtube-api-to-upload-videos-from-your-site/#comments</comments>
		<pubDate>Wed, 15 Apr 2009 02:55:26 +0000</pubDate>
		<dc:creator>yalamber</dc:creator>
				<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[google]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpizabi]]></category>
		<category><![CDATA[socialnetwork]]></category>
		<category><![CDATA[youtube api]]></category>

		<guid isPermaLink="false">http://yalamber.com/?p=158</guid>
		<description><![CDATA[I wanted to create a video site but lacked the server resources to run it, I am using a shared server, it has ffmpeg but when converting a video it takes lot&#8217;s of system resources. I successfully made the fmpeg &#8230; <a href="http://blog.yalamber.com/2009/04/15/using-youtube-api-to-upload-videos-from-your-site/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I wanted to create a video site but lacked the server resources to run it, I am using a shared server, it has ffmpeg but when converting a video it takes lot&#8217;s of system resources. I successfully made the fmpeg video site, But didn&#8217;t decide to use it. I searched for youtube APIs and i came to know we could simply use the youtube api to upload videos from our site to youtube. So i decided to use it for my video site. Below is step by step tutorial on using youtube api to upload videos from your site to youtube, I used the clientLogin method of youtube api to upload videos.</p>
<ol>
<li>First get the developer key for using youtube api.<br />
Go to http://code.google.com/apis/youtube/dashboard/ and regsiter a developer key<br />
You will be given client id and  developer key. Note it down, it will be used in your own application later.</li>
<li>Get the php client libraries, Go to http://framework.zend.com/download/gdata</li>
<li>extract it to your server. I assume you put the Zend direcctory in your server document root.</li>
<li>Create a form in your site as below which i assume will be pointed to upload.php file in your srver.</li>
</ol>
<pre class="brush: html">
&lt;form action=&quot;upload.php&quot;  method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
&lt;select name=&quot;videoCategory&quot;&gt;
&lt;option value=&quot;Autos&quot;&gt;Autos &amp;amp;amp; Vehicles&lt;/option&gt;
&lt;option value=&quot;Music&quot;&gt;Music&lt;/option&gt;
&lt;option value=&quot;Animals&quot;&gt;Pets &amp;amp;amp; Animals&lt;/option&gt;
&lt;option value=&quot;Sports&quot;&gt;Sports&lt;/option&gt;
&lt;option value=&quot;Travel&quot;&gt;Travel &amp;amp;amp; Events&lt;/option&gt;
&lt;option value=&quot;Games&quot;&gt;Gadgets &amp;amp;amp; Games&lt;/option&gt;
&lt;option value=&quot;Comedy&quot;&gt;Comedy&lt;/option&gt;
&lt;option value=&quot;People&quot;&gt;People &amp;amp;amp; Blogs&lt;/option&gt;
&lt;option value=&quot;News&quot;&gt;News &amp;amp;amp; Politics&lt;/option&gt;
&lt;option value=&quot;Entertainment&quot;&gt;Entertainment&lt;/option&gt;
&lt;option value=&quot;Education&quot;&gt;Education&lt;/option&gt;
&lt;option value=&quot;Howto&quot;&gt;Howto &amp;amp;amp; Style&lt;/option&gt;
&lt;option value=&quot;Nonprofit&quot;&gt;Nonprofit &amp;amp;amp; Activism&lt;/option&gt;
&lt;option value=&quot;Tech&quot;&gt;Science &amp;amp;amp; Technology&lt;/option&gt;
&lt;/select&gt;
&lt;label for=&quot;title&quot;&gt;Title&lt;/label&gt;
&lt;input id=&quot;title&quot; name=&quot;title&quot; type=&quot;text&quot;&gt;
&lt;label for=&quot;description&quot;&gt;Description&lt;/label&gt;
&lt;textarea id=&quot;description&quot; name=&quot;description&quot; rows=&quot;5&quot;&gt;&lt;/textarea&gt;
&lt;label for=&quot;keywords&quot;&gt;Kewords (use comma , to separate)&lt;/label&gt;
&lt;input id=&quot;keywords&quot; name=&quot;keywords&quot; value=&quot;&quot; type=&quot;text&quot;&gt;
&lt;br class=&quot;clr&quot; /&gt;
&lt;input value=&quot;Next -&gt; choose video&quot; name=&quot;add&quot; type=&quot;submit&quot; /&gt;
&lt;/form&gt;
</pre>
<p>Create upload.php</p>
<pre class="brush: php">

&lt;?php

if(isset($_POST[&#039;add&#039;],$_POST[&#039;videoCategory&#039;],$_POST[&#039;title&#039;],$_POST[&#039;description&#039;]))
{
//add the video meta data to session
$_SESSION[&#039;vidmeta&#039;][&#039;category&#039;] = $_POST[&#039;videoCategory&#039;];
$_SESSION[&#039;vidmeta&#039;][&#039;title&#039;] = $_POST[&#039;title&#039;];
$_SESSION[&#039;vidmeta&#039;][&#039;description&#039;] = $_POST[&#039;description&#039;];
$_SESSION[&#039;vidmeta&#039;][&#039;keywords&#039;] = $_POST[&#039;keywords&#039;];

//application id change this to our applicationId
$applicationId = &#039;onnepalvideosite&#039;;
//client id change this to our own client id
$clientId = &quot;ytapi-xxxxxx-xxxx-xxxxx&quot;;
//developer key change this to your own key
$developerKey = &quot;xxxxxxx-xxxxxxx-xxxxxxxxx-xxxxxxx&quot;;
//include zend loader
require_once(&#039;Zend/Loader.php&#039;); // the Zend dir must be in your include_path
//include youtube class
Zend_Loader::loadClass(&#039;Zend_Gdata_YouTube&#039;);
//include the client login class
Zend_Loader::loadClass(&#039;Zend_Gdata_ClientLogin&#039;);
//Client login
$authenticationURL= &#039;https://www.google.com/youtube/accounts/ClientLogin&#039;;
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username = &#039;your username here&#039;,
$password = &#039;our password here&#039;,
$service = &#039;youtube&#039;,
$client = null,
$source = &#039;onnepal&#039;, // a short string identifying your application
$loginToken = null,
$loginCaptcha = null,
$authenticationURL);

$yt = new Zend_Gdata_YouTube($httpClient, $applicationId, $clientId, $developerKey);
// create a new VideoEntry object
$myVideoEntry = new Zend_Gdata_YouTube_VideoEntry();

$myVideoEntry-&gt;setVideoTitle($_POST[&#039;title&#039;]);
$myVideoEntry-&gt;setVideoDescription($_POST[&#039;description&#039;]);
// The category must be a valid YouTube category!
$myVideoEntry-&gt;setVideoCategory($_POST[&#039;videoCategory&#039;]);

// Set keywords. Please note that this must be a comma-separated string
// and that individual keywords cannot contain whitespace
$myVideoEntry-&gt;SetVideoTags($_POST[&#039;keywords&#039;]);

$tokenHandlerUrl = &#039;http://gdata.youtube.com/action/GetUploadToken&#039;;
$tokenArray = $yt-&gt;getFormUploadToken($myVideoEntry, $tokenHandlerUrl);
$tokenValue = $tokenArray[&#039;token&#039;];
$postUrl = $tokenArray[&#039;url&#039;];
$nextUrl = &#039;http://www.yoursite.com/yt.php&#039;;
print &lt;&lt;&lt; END
&lt;br /&gt;&lt;form action=&quot;${postUrl}?nexturl=${nextUrl}&quot;
method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
&lt;input name=&quot;file&quot; type=&quot;file&quot;/&gt;
&lt;input name=&quot;token&quot; type=&quot;hidden&quot; value=&quot;${tokenValue}&quot;/&gt;
&lt;input value=&quot;Upload Video File&quot; type=&quot;submit&quot; /&gt;
&lt;/form&gt;
END;
}
?&gt;
</pre>
<p>This code takes the category, title, description and keywords from the form and generates a form to upload video to youtube. You can then upload video to youtube using the form.<br />
Next make yt.php file which is the $nexturl file, $nexturl is the location to which youtube will redirect after the upload is complete. YouTube appends <code>id</code> and <code>status</code> parameters to the URL as shown in the following example</p>
<pre>http://www.yoursite.com/yt.php?status=200&amp;id=JPF-DXF7hzc</pre>
<p>Afterou get the youtube video id in your yt.php file you can add it to your own database to show videos in your site. You can do anything you wish with the variables you get through yt.php.I hope it will be help ful to all wishing to use youtube apis to upload video.</p>
<p>This can also be implemented to phpizabi sites.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.yalamber.com/2009/04/15/using-youtube-api-to-upload-videos-from-your-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
