Powered By
Showing posts with label API. Show all posts
Showing posts with label API. Show all posts

Load Youtube toprated videos using simplexml_load_file PHP

View Comments
add to del.icio.us
saved by 0 users
  In this post I will show you how to fetch the you tube top rated videos just with built in PHP functions instead of using zend data api libraries.  Zend data api is the best and optimized way to do this task but rather than including and working with zend and zend data api you can just do this with php built-in functions by reading the you tube feeds for the top rated videos.

 So here we go.
General feed url of youtube is

http://gdata.youtube.com/feeds/api/standardfeeds/FEED_IDENTIFIER 
 
Youtube feeds URL for the top rated videos is
http://gdata.youtube.com/feeds/api/standardfeeds/top_rated

Here you can replace top_rated with




Fore more info regarding this

http://code.google.com/apis/youtube/2.0/developers_guide_php.html

So we have to read the feeds from the above url, then you can display it where ever you want.

We have the top rated videos as xml so we need to parse it using php function "simplexml_load_file() " .
To do this in php.ini we need to enable the url include option to On if it is not already turned on.

Get the feeds in a variable

                     $url="http://gdata.youtube.com/feeds/api/standardfeeds/top_rated";
                     $comments =simplexml_load_file($url); // Php built in function


So we have  top rated videos in $comments  , we need to parse it using foreach and display it in the following way.

 Here the feed is in yahoo feed format so you to mention the feed as yahoo and then you can parse the media group under entry tag.

      $media = $video->children('http://search.yahoo.com/mrss/');
So from this we can easily parse all the data from the youtube feeds.

Download the source for your reference.





You can also do all other functionality like searching a video or displaying particular video comments, recent videos and more using the above method. Its very easier than the zend data api. Try it out. Leave the comments if you have any problem
Read More

Retrieve Documents List from Google Docs using GData Java Client Library

View Comments
add to del.icio.us
saved by 0 users
You can connect and retrieve data from any of the Google services by using Google API. Here we are going to use one such application for retrieving list of documents from Google Docs using the java client library provides by Google. You can download that open source stuffs latest version from gdata-java-client. The steps for installing the library and its dependencies to your local system can be found in "Getting started with Google Data java Client Library".
If you are using eclipse IDE for working with Java, then the steps of installation are more easy and that can be found in "Coding in the Shade". After successfully installing those libraries and contents. Now we can start developing our first and simple application to retrieve the document list from Google Docs.

Now Create a java project and add the necessary External jars to project library. As we are going to develop a application to communicate with Google Docs add the "gdata-docs-3.0.jar" and "gdata-docs-meta-3.0.jar" in specific for this project.

Download full Code here

In the downloaded code you can find the import statements, which imports three important class to get feeds from Google Docs.


import com.google.gdata.client.docs.DocsService;
import com.google.gdata.data.docs.DocumentListEntry;
import com.google.gdata.data.docs.DocumentListFeed;

First instance for the DocsSrevice class is created by passing the applications information as parameters to the constructor. And the users credentials such as username with domain name and corresponding password are set using the setUserCredentials() method.


DocsService client = new DocsService("yourCo-yourAppName-v1");
client.setUserCredentials("UrEmailID@gmail.com","Password");

Then the getFeed() method of DocsService class is invoked, the url from which the feeds are to be obtained are passed as the argument. The feeds obtained by getFeed() is assigned to instance of DocumentListFeed. Each entry in the feed are extracted using the DocumentListEntry class.


URL feedUri = new URL("http://docs.google.com/feeds/default/private/full/");
DocumentListFeed feed = (DocumentListFeed) client.getFeed(feedUri, DocumentListFeed.class);

for (DocumentListEntry entry : feed.getEntries()) {
printEntry(entry);
}

Then each documents information be obtained as follows:


public void printEntry(DocumentListEntry entry) {
String resourceId = entry.getResourceId();
String docType = entry.getType();

System.out.println("'" + entry.getTitle().getPlainText() + "' (" + docType + ")");
System.out.println(" link to Google Docs: " + entry.getDocumentLink().getHref());
System.out.println(" resource id: " + resourceId);
System.out.println(" doc id: " + entry.getDocId());
}

This is a initiation, you can process a lot more using those API. To get more information about working with Google Docs you can check the following links:
Thank You for Reading this Post... Happy Blogging.
Read More

Google Account Authentication using ActionScript in Adobe AIR

View Comments
add to del.icio.us
saved by 0 users
Google Supports developers by providing lots of API for each and every service they provide. By using those APIs, developers can communicate with Google and get feeds from any of thier services by developing a web based application or a installable client application. Before starting to get feeds and post feeds to Google accounts from the application, the developers must get the user's Google account authenticated. To do that user credentials such as email id with password must be send to Google and if the credentials are correct then Google will send back a authorizing token using which developers can start getting feeds and process them.


To authenticate a user, use Google account API, that allow third party application to get limited access to a user's Google accounts for certain types of activities. The Google Authorization Service manages authentication, authorization, and access control to user accounts, subject to approval from the account holder. Google offers several account authorization APIs to accomodate different types of access. Google provides three types of access authorization methods. They are
Now let me explain authenticating with ClientLogin for installed desktop application and will explain others in the future post. I have used action script with flex SDK, but u can try with other technologies with minor changes in the code.

Download the Full Code
First send a http request to Google using HTTPService class with the user name and password by POST.

<mx:HTTPService id="Google"
url="https://www.google.com/accounts/ClientLogin"
method="POST"
contentType="application/x-www-form-urlencoded"
result="handleLoginPlain(event);"
fault="handleLoginFault(event);" >
<mx:request xmlns="">
<accountType>HOSTED_OR_GOOGLE</accountType>
<Email>UrEmail@gmail.com</Email>
<Passwd>UrPassword</Passwd>
<source>OrganizationName-AppName-Version</source>
<service>ServiceUrgoing2use</service>
</mx:request>
</mx:HTTPService>
Then scripts must be written to handle the result and failure.

<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;

[Bindable]
private var authString:String;

public function init():void {
Google.send();
}

private function handleLoginPlain(event:ResultEvent):void
{
var textindex:int;

trace("Event result "+event.result.toString());
authString = event.result.toString();
textindex = authString.search("Auth");
authString = authString.substring(textindex);
authString = authString.replace("Auth=","");
textindex = authString.length;
textindex = textindex - 1;
authString = authString.substring(0,textindex);

trace("Auth String "+authString);
}

public function handleLoginFault(event:FaultEvent):void
{
Alert.show("Login Error");
trace("Client Login Error Message"+event.message);
}
]]>
</mx:Script>
Explanation of the code:
First all the neccessary information for making a request are set in the HTTPService method. Dont forget to give a valid email and password in the class, otherwise you cannot get authorization. Then the request is send only in the scripting part in the init() function with will be called when application load completes by setting the tag "applicationComplete="init()"". The handlers are already set in the mx tag to handle the result event and failure event. A success response contains the authorization token, labeled "Auth", in the body of the response. Your application must reference this token in each request to the Google service for this user. Additional cookies, labeled "SID" and "LSID", are not currently active and should not be used. A failure response contains an error code and a URL to an error page that can be displayed to the user.

Check this links to get still more information from Google:
Read More