Showing posts with label Web Services. Show all posts
Showing posts with label Web Services. Show all posts

Friday 14 November 2014

Current time zone for a city- Free API

Current time zone for a city- Free API

Get TimeZone & Local time from Latitude/Longitude

$localtime = 0;
$latitude = '40.71417';
$longitude = '-74.00639';
try {
    $client = new Zend_Http_Client('' . $latitude . '/' . $longitude);
    $response = $client->request('GET');
    $xmlData = $response->getBody();
    if (!empty($xmlData)) {
        $xmlData = simplexml_load_string($xmlData);  

} catch (Exception $e) {
    echo 'Error' . $e->getMessage();


SimpleXMLElement Object
    [version] => 1.0
    [location] => SimpleXMLElement Object
            [latitude] => 40.71417
            [longitude] => -74.00639
    [offset] => -5
    [suffix] => R
    [localtime] => 13 Nov 2014 01:42:07
    [isotime] => 2014-11-13 01:42:07 -0500
    [utctime] => 2014-11-13 06:42:07
    [dst] => Unknown

Get Latitude/Longitude from address


Monday 27 October 2014

Zend Gdata Youtube API - Search Video - View Video Detail

Zend Gdata Youtube API - Search Video - View Video Detail

Youtube API is very useful to show the youtube videos in your website. You don't required any account for search the video. You can filter the video by query string, category, limit no of records & you can see even video detail.
You can also upload OR do changes in uploaded videos but for this you need youtube account.On the behalf of my experience I am presenting some easy example which let you understand the youtube API. These example are testing with zend framework 1.12. Please let me your thoughts on this...

Search Videos by Category
$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();
$query->category = 'Comedy/dog';
//$query->setCategory('Comedy/dog'); OR 
$videos = $yt->getVideoFeed($query);

Search Videos by query string
$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();
$query->videoQuery = 'dogs';
$videos = $yt->getVideoFeed($query);

List Top Rated Videos
$yt = new Zend_Gdata_YouTube();
$videos = $yt->getTopRatedVideoFeed();

List Today's Top Rated Videos
$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();
$videos = $yt->getVideoFeed($query);

List videos by viewCount & Add limit
$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();
$query->orderBy = 'viewCount';
$query->startIndex = 10;
$query->maxResults = 20;
$videos = $yt->getVideoFeed($query);

Example In Zend Framework 
class IndexController extends Zend_Controller_Action {

    public function init() {
        /* Initialize action controller here */

    public function indexAction() {

        // action body

    function printVideoFeed($videoFeed) {
        foreach ($videoFeed as $videoEntry) {

    function printVideoEntry($videoEntry) {
        echo '\n Video: ' . $videoEntry->getVideoTitle();
        echo '\n Video ID: ' . $videoEntry->getVideoId();
        echo '\n Updated: ' . $videoEntry->getUpdated();
        echo '\n Description: ' . $videoEntry->getVideoDescription();
        echo '\n Category: ' . $videoEntry->getVideoCategory();
        echo '\n Tags: ' . implode(", ", $videoEntry->getVideoTags());
        echo '\n Watch page: ' . $videoEntry->getVideoWatchPageUrl();
        echo '\n Flash Player Url: ' . $videoEntry->getFlashPlayerUrl();
        echo '\n Duration: ' . $videoEntry->getVideoDuration();
        echo '\n View count: ' . $videoEntry->getVideoViewCount();
        echo '\n Rating: ' . $videoEntry->getVideoRatingInfo();
        echo '\n Geo Location: ' . $videoEntry->getVideoGeoLocation();
        echo '\n Recorded on: ' . $videoEntry->getVideoRecorded();

        foreach ($videoEntry->mediaGroup->content as $content) {
            if ($content->type === "video/3gpp") {
                echo '
 Mobile RTSP link: ' . $content->url;
        echo "\n\n";

    function youtubeAction() {
        $yt = new Zend_Gdata_YouTube();
        $query = $yt->newVideoQuery();
        $query->category = 'Comedy/dog';
        //$query->setCategory('Comedy/dog'); OR 
        $videos = $yt->getVideoFeed($query);



Video: My 200th Video
Video ID: h23oPnh1WJM
Updated: 2014-10-27T00:30:41.000Z
Description: Please subscribe to my channel and my vlog channel! I make new videos here every Wednesday and make vlogs during my majestical daily life. JennaMarbles Jenna...
Category: Comedy
Watch page:
Flash Player Url:
Duration: 263
View count: 3640139
Rating: Array
Geo Location:
Recorded on:
Mobile RTSP link: rtsp://
Mobile RTSP link: rtsp://

Saturday 25 October 2014

How do I get a YouTube video thumbnail from the YouTube

How do I get a YouTube video thumbnail from the YouTube

How to get youtube video thumbnail
1. First Get the Video URL (Video URL is like
2. Get the youtube video Id from Video URL (Video id is like J0Qu6eyyr4c)
3. Now video thumbnail is ready.

Small Video Image
How do I get a YouTube video thumbnail from the YouTube 

Bigger Video Thumbnail
How do I get a YouTube video thumbnail from the YouTube

Large Video Thumbnail
How do I get a YouTube video thumbnail from the YouTube

Thursday 21 August 2014

XML Interview Questions And Answers

XML Interview Questions And Answers

What is full Form XML?
Extensible Markup Language.

What is XML?
It is text-based standard design for interchange the information between two application. There are no predefined tags and attributes in XML. you can create your own tags and attributes in tag.

Who created the XML?
Jon Bosak

Why It is so popular?
  • It is free standard for exchange information.
  • It is independent of language.
  • It is independent of Hosting Server 
  • Human Readable.
  • You can create your Own tags in XML. 
  • Used for embed images, video etc

Where XML is used?
It is used to exchange the information between two application. Information can also be exchanged between two different application which is running on different OR same server. It is used in Web Application, Mobile Application (IOS, Android, Iphone, window Phone) for providing the API. It is also used AS installer in web application, you can set the application configuration in XML file.

Why it is used?
  • It is Opensource.
  • It is easy to understand.
  • you can create your own tags. 
  • Independent of languages and OS.
  • You can embed photo, videos in XML.

What is file extension of XML?

How the raw XML file can be viewed in a browser?
Raw XML files can be viewed in Mozilla, Firefox, Opera, Internet Explorer and in Netscape. For make XML documents to display like nice web pages, you will have to add some display information.

How to parse XML in PHP?

What is a CDATA section in XML?
The CDATA is used when you don't want some text data be parsed by the XML parser.
Now, above data will not parse.

What is XQuery?
Xquery is a query language that is used to retrieve data from XML documents. You can add, update, delete and list the XML with use of XQuery.

What i XMLA ?
It is protocol of Microsoft  for XML-messaging used for exchanging data between client and servers.

What is XSL?
XSL is a language used for expressing style sheets. An XSL style sheet is a file that describes the way to display an XML document.

What is the difference between XML and HTML?
Used for displaying information. Used for data representation.
HTML is used to mark up text so it can be displayed to users. XML is used to mark up data so it can be processed by computers.
HTML describes both structure (e.g. <p>, <h2>, <em>) and appearance (e.g. <br>, <font>, <i>) XML describes only content
HTML uses a fixed, unchangeable tags There is no predefined tags, you can create your own.

What are the benefits of XML?
Contains machine-readable context information- Tags, attributes and element structure provide context information. Can embed multiple data types - XML documents can contain any possible data type - from multimedia data (image, sound, video) to active components (Java applets, ActiveX).

What is a well-formed XML document?
If a document is syntactically correct it can be called as well-formed XML documents.
Every open tag must be closed.
The open tag must exactly match the closing tag: XML is case-sensitive.
All elements must be embedded within a single root element.
Child tags must be closed before parent tags.
A well-formed document has correct XML tag syntax, but the elements might be invalid for the specified document type.

How to add CSS in XML File?
<!--xml-stylesheet type="text/css" href="/css/mystyle.css"?-->

How to add CSS in XML File?
    any code........

Thursday 7 August 2014

Goole Map - Track your moving Position on google map- html5

Goole Map - Track your moving Position on google map- html5

This will enable to you get the current position of your location in mobile. First it will tell your current position on the Google map in form of Pushpin. When you start changing your position then pushpin will start moving. It will be follow you. But GPS and internet must be support by your mobile and off-course it should be enabled in your mobile. It will also work in 2G/3G/4G. It will give your more accurate when you are in City area.

How its work:
It will check your current position with use of browser html5 property. Thats why it ask "Are you want to share your current location".To see your position you must give the access of your current position to the browser. After getting your position it simply plot on google map. When you change your position it recheck the position with use of GPS and update the pushpin on google map.


    body {font-family: Helvetica;font-size:13pt;padding:0px;margin:0px}
    #map_canvas{display:none; height:100%; width:100%; position:relative;z-index:1;}
    #current {padding:5px; background-color:#000; position:unset; left:0px;z-index:2;text-align:center;width:90%;opacity:0.4;color:#FFF;border-radius:0px 0px 5px 5px; font-weight:bold;}
    #btnCont{position:absolute; bottom:0px; left:0px; width:100%; text-align:center;z-index:2;}</style>

<div id="current">
<div id="map_canvas" style="height: 300px; width: 800px;">
<div id="btnCont" style="display: none;">
<button onclick="startAgain();"> Restart Tracking</button>
    <button onclick="stopTracking();"> Stop Tracking</button>
<script charset="utf-8" src="//" type="text/javascript"></script>
<script src="//" type="text/javascript"></script>

    var gmap = null;
    var markers = [];
    var opts = {
        enableHighAccuracy: true,
        timeout: 60000,
        maximumAge: 0
    function initialiseMap(){
        var myOptions = {
            minZoom : 3,
            zoom: 10,
            mapTypeControl: true,
            mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
            navigationControl: true,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
            mapTypeId: google.maps.MapTypeId.ROADMAP      
        gmap = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    function initialise(){
            document.getElementById('current').innerHTML="Functionality not available";
    function handle_errors(error){
        var error_str='';
            case error.PERMISSION_DENIED: 
                error_str="User(you) did not share your geolocation";
            case error.POSITION_UNAVAILABLE: 
                error_str="Could not detect current position";
            case error.TIMEOUT: 
                error_str="retrieving position timed out";
                error_str="unknown error";
    function showPosition(p){
        if(gmap == null){
            document.getElementById('map_canvas').style.display = 'block';
        var latitude = parseFloat( p.coords.latitude );
        var longitude = parseFloat( p.coords.longitude );
        document.getElementById('current').innerHTML="Lat = " + latitude.toFixed(2) +" and Long = " + longitude.toFixed(2);
        var location = new google.maps.LatLng( latitude , longitude);

        var marker = new google.maps.Marker({
            position: location,
            map: gmap,
            title:"You are here"
        var infowindow = new google.maps.InfoWindow({
            content: "<strong>This is your current location.</strong>"
        google.maps.event.addListener(marker, 'click', function() {
        document.getElementById('btnCont').style.display = 'block';
    function setAllMap(map) {
        for (var i = 0; i &lt; markers.length; i++) {
    function deleteMarkers() {
        markers = [];
    var watchID = navigator.geolocation.watchPosition(trace,handle_errors,opts);
    function trace(position){
    function startAgain(){
        watchID = navigator.geolocation.watchPosition(trace,handle_errors,opts);
    function stopTracking(){
    google.maps.event.addDomListener(window, 'load', initialise);


Tuesday 20 May 2014

Difference between WebService and API

Difference between WebService and API

Web Service
Interaction between two machines over a network. Interaction between two API.
Uses SOAP, REST, and XML-RPC as a means of communication. It may use any way to communication
Web Services involves calling of system. We can render form in one line, one by one element, element OR  decorator OR error separately.
Web service might not contain a complete set of specifications and sometimes might not be able to perform all the tasks that may be possible from a complete API. An API consists of a complete set of rules and specifications for a software program to follow in order to facilitate interaction.
All Web services are APIs All APIs are not Web services
A Web service always needs a network for its operation API doesn't need a network for its operation
WebServices are services available over internet. You can call these services and get so information in your application without know how it works. For example weather webservices gives you information about the city weather. API is a collection of class which provide you some functionality like Google api gives google-search.

Friday 16 May 2014

Zend Framework - Free Google Analytics API

Zend Framework - Free Google Analytics API

After making a successful website, we add an  google analytics code to track the activities on our website. It gives all tracking information from all geo regions on all the pages.
It help us to know daily, monthly, yearly visiter in different countries and list of pages which searched most.

But creating a report on the behalf of analytics data, is difficult stuff because it take a lot of lot of time.

Following are simplest way to get the google analytics data.
        $email = 'ADSENSE_GMAIL_USERNAME';
        $password = 'ADSENSE_GMAIL_PASSWORD';
        /** Get Connection with Analytics Account * */
        $client = Zend_Gdata_ClientLogin::getHttpClient($email, $password, Zend_Gdata_Analytics::AUTH_SERVICE_NAME);
        $service = new Zend_Gdata_Analytics($client);
        /** Get Connection with Analytics Account * */
        /** Get Analytics Account Information * */        
        $profileResults = $service->getDataFeed($service->newAccountQuery()->profiles())->current()->getExtensionElements();
        foreach($profileResults as $profileResult){
            $attributes = $profileResult->getExtensionAttributes();
            $name = $attributes['name']['value'];
            $value = $attributes['value']['value'];
                $profileId = $value;
            echo "$name : $value\n";
        /** Get Analytics Account Information * */
        /** Get Analytics Data */         
        $dimensions = array(

        $query = $service->newDataQuery()->setProfileId($profileId)
                ->addSort(Zend_Gdata_Analytics_DataQuery::METRIC_VISITS, true)
                ->addSort(Zend_Gdata_Analytics_DataQuery::METRIC_BOUNCES, false)
        echo "\nVisits : Bounce \n\n";
        foreach ($dimensions as $dim) {
                   $result = $service->getDataFeed($query); 
        }catch(Exception $e){
            echo $e->getMessage();die;

        foreach ($result as $row) {
            echo $row->getMetric('ga:visits') . "\t";
            echo $row->getValue('ga:bounces') . "\n";
        /** Get Analytics Data */

As an above example, you can extract all information from the Google Analytics API and stored in array or Object then can download into csv OR Excel format.

Wednesday 23 April 2014

Google Dynamic Charts - Bar Pie and Line Chart - code snippets

One image express thousand words, that's why we use images in our daily life, Personal & professional.
Reading full report is a difficult task and need hours to understand, but we get the chart of that report Its easy and need only few minutes to understand. That's why we use chart in our professional life.

Chart can have different types and each have its own quality. For Example
Pie Chart: It display percentage values as a slice of a pie.
Bar Chart: It display with rectangular bars with lengths proportional to the values that they represent. The bars can be plotted vertically OR horizontally.
line chart is a two-dimensional scatterplot of ordered observations where the observations are connected.

Google Create different types of chart on the fly. No installtion and no code download is required. Just pass all parameter and your desired chart is ready.

Its very quick. see below few examples. you will understand how Google make easy. 
Pie chart
Pie chart Example
<img alt="Pie chart Example" src=";chd=t:30,20,50&amp;cht=p3&amp;chl=Arun|Kuldeep|Ajit" title="Pie chart Example" />

Bar Chart

Bar chart Example
<img alt="Bar chart Example" src=";cht=bvs&amp;chd=t:_,30,-30,50,80,200&amp;chxt=y" title="Bar chart Example" />

Line Chart

Line chart Example
<img alt="Line chart Example" src=",s,FFFFFF00&amp;chxl=1:|16%2F04%2F2014|18%2F04%2F2014|20%2F04%2F2014|




" title="Line chart Example" />

Tuesday 8 April 2014

Facebook User Profile Get Custom Picture of Facebook User

Facebook User Profile Get Custom Picture of Facebook User

Today, Every one use the Facebook for social networking whether he is Student, Working Women, House wives, IT Professional or Business man etc. Everyone open Facebook account at-least once a day.

Due to huge use of Facebook profiles.  All Web application start integrate the Facebook plugins in their websites.
They Start using plugins like Registration, Like plugin, Comment box, Login/Logout functionalists and Chat implement.

Many times, we need to show the Profile pictures of Facebook users in web page. Sometimes you have to show the custom size of profile picture. If there is requirement of showing the custom images of profile user then you are very right place. Here we are giving you lot of example of custom size.

You can show the profile pictures in unlimited sizes. Just fill the height width parameter in URL and your profile picutre is ready. to show the Profile picture you need 1 parameter only and that is UID. UID is user id and facebook users and its unique.

If we have facebook profile Id, then we can get different facebook profile images with the following URLs.[UID]/picture?type=square[UID]/picture?width=[WIDTH]&height=[HEIGHT]
Here [UID] is Facebook Profile Id and [WIDTH]/[HEIGHT] is width/height

Very Small Profile Image(50 X 50)
Very Small Profile Image(50 X 50)
Profile Thumbnail Profile Thumbnail
Large Profile Image (300 X 300)
Large Profile Image (300 X 300)

5 Best Related Posts are Following:1. Facebook comments box for website
2. Facebook login with javascript SDK example
3. Facebook User Profile Get Custom Picture of Facebook User
4. Facebook Login with JavaScript
5. Firebase Chat with Facebook and Twitter Integration

Thursday 3 April 2014

Facebook Login with JavaScript

Follow Simple Steps to Integrate "Facebook Login" with JavasScript in your Web Application.

  • Login in
  • "Create a New App" in
  • Fill all required Information
  • Settings => App PlateForm=>Click on "Website" then add detail
  • In "Status & Review", Click on "Yes" to activate for public

Get the "App Id" and use in Following Example
        <title>Facebook Login Integration with JavaScript</title>
        <script src="//"></script>

        <div id="fb-root">
            window.fbAsyncInit = function() {
                    appId      : 'XXXXXXXX',//your appid
                    status     : true, 
                    cookie     : true,
                    xfbml      : true,
                    oauth      : true                    
                FB.Event.subscribe('auth.authResponseChange', function(response) {                    
                    // Here we specify what we do with the response anytime this event occurs. 
                    if (response.status === 'connected') {
                    } else if (response.status === 'not_authorized') {
                        // In this case, the person is logged into Facebook, but not into the app, so we call                        
                    } else {
                        // In this case, the person is not logged into Facebook, so we call the login()                         
            function saveuserdetail() {
                //console.log('Welcome!  Fetching your information.... ');
                FB.api('/me', function(response) {                    
                        type: "POST",
                        url: '/url_to_save_detail',
                        data: response,
                        success: function(msg){
                        dataType: 'json'
                var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
                js = d.createElement('script'); = id; js.async = true;
                js.src = "//";
        <div class="fb-login-button">
Login with Facebook</div>

Facebook Login URL:
websiteLoginURL: After login which page of your website should redirect.
appId: Application Id of

Sunday 22 September 2013

Soap Interview Questions and Answers

Question:  Explain the SOAP?
Answer: SOAP stands for Simple Object Access Protocol. SOAP is an XML-based protocol for exchanging information between two computers over the internet. It enables you to Remote Procedure Calls (RPC) transported via HTTP.
Following are the SOAP characteristics. 
SOAP is for communication between applications
SOAP is a format for sending messages
SOAP is designed to communicate via Internet
SOAP is platform independent
SOAP is language independent
SOAP is simple and extensible

Question: Where is SOAP used?
Answer: It is used to exchanges the information between two computers over the internet. For this we used the XML in special format to send and receive the Information.

Question: Difference between XML and SOAP?
Answer: XML is language whereas SOAP is protocol. 

Question: Difference between JSON and SOAP?
Answer: JSON is standard to represent human-readable data.  SOAP is a protocol specification for transmitting information and calling web services use XML.

Question: What are the rules for using SOAP?

Question: What is SOAP Envelope Element?

Question: What does SOAP Namespace defines?
Answer: The namespace defines the Envelope as a SOAP Envelope. If a different namespace is used, the application generates an error and discards the message.

Question: What is the SOAP encodings?
Answer: The envelope specified the encoding for the body.  This is a method for structuring the request that is suggested within the SOAP specification, known as the SOAP serialization. It's worth noting that one of the biggest technical complaints against SOAP is that it mixes a specification for message transport with a specification for message structure.  

Question: What does SOAP encodingStyle Attribute defines?
Answer: The encodingStyle attribute is used to define the data types used in the document(s). This attribute may appear on any SOAP element, and applies to the element's contents and all child element(s).

Question: What are the Different Transport Protocols?
Answer:  SOAP, REST,  SMTP, raw TCP Socket.

Question: What is UML?
Answer: Unified Modeling Language

Question: can we send soap messages with attachments.
Answer: Yes, We can send photos/Audio/video with soap messages as an attahcment. SOAP messages can be attached with MIME extensions that come in multipart/related. It is used to send messages using the binary data with defined rules. The SOAP message is carried in the body part with the structure that is followed by the message of the SOAP.

Question: What is the difference between SOAP and other remote access techniques?
Answer: SOAP is simple to use and it is non-symetrical whereas DCOM or CORBA is highly popular and usually have complexity in them. It also has the symmetrical nature in it. 

Question: What are the problems faced by users by using SOAP?

Answer:  There is a problem to use this protocol as firewall is a security mechanism that comes in between. This ock all the ports leaving few like HTTP port 80 and the HTTP port is used by SOAP that bypasses the firewall. It is a serious concern as it can pose difficulties for the users. There are ways like SOAP traffic can be filtered from the firewalls.