API

What is API ?


Abbreviation of application program interface, a set of routines, protocols, and tools for building software applications. A good API makes it easier to develop a program by providing all the building blocks. A programmer then puts the blocks together.

Most operating environments, such as MS-Windows, provide an API so that programmers can write applications consistent with the operating environment. Although APIs are designed for programmers, they are ultimately good for users because they guarantee that all programs using a common API will have similar interfaces. This makes it easier for users to learn new programs.


Now a day most of organization provide the API for retrieve information from their global database. So social network sites provide the API for retrive friend list,news feed,current activities etc.
Example Facebook API,Tweeter API,Linked in API etc. Other organization also provide their API for retrieve valuable data from the global database. Ex -Google API for MAP,Contact,Translation and many more .So API make easier to develop a Application as per their requirement.


Search Linked In People In your web application using linked in Javascript API

Step 1

Go to this below URL 

Step 2
Add your apps for generate API key .See Figure 1
Figure 1



Step 3

Fill up all required information as per your requirement .See Figure 2
Figure 2

Then click on Add Application Button for generate API Key .See Figure 3
Figure 3
Step 4

Copy the Below Code and paste in your application page .


<script type="text/javascript" src="http://platform.linkedin.com/in.js">
  api_key: YOUR_API_KEY

</script>


<script type="text/javascript">
function searchClick() {
  if (!IN.ENV.auth.oauth_token) {
    alert("You must login w/ LinkedIn to use the Search functionality!");
    return;
  }

  IN.API.PeopleSearch()
    .fields("id", "firstName", "lastName")
    .params({
      "first-name": document.searchform.firstName.value,
      "last-name": document.searchform.lastName.value,
      "company": document.searchform.company.value
    })
    .result(function(result, metadata) {
      setSearchResults(result, metadata);
    });
}

function setSearchResults(result, metadata) {
  searchHTML = "Search Results (" + result.numResults + "):<ul>";
  console.log(result.people.values);
  for (i in result.people.values) {
    searchHTML = searchHTML + "<li>";
    searchHTML = searchHTML + result.people.values[i].firstName + " ";
    searchHTML = searchHTML + result.people.values[i].lastName + " ";
    searchHTML = searchHTML + " (memberToken: " + result.people.values[i].id + ")</li>";
  }
  searchHTML = searchHTML + "</ul>";
  
  document.getElementById("searchresults").innerHTML = searchHTML;
}
</script>

<!-- need to be logged in to use Search; if not, offer a login button -->
<script type="IN/Login"></script>
<p>Basic test of the People Search API via Connect. <br />
You must click the button (pressing Enter doesn't work).</p>
<form name="searchform" onsubmit="return false;">
  First Name:&nbsp;<input type="text" name="firstName"><br/>
  Last Name:&nbsp;<input type="text" name="lastName"><br/>
  Company:&nbsp;<input type="text" name="company"><br/>
  <input type="button" name="search1" value="Search LinkedIn!" onclick="searchClick()">
</form>
<div id="searchresults"></div>


Step 5

Copy the API Key and Paste in code where it required .

Step 6

Run your application and enjoy it.....


Note :Project should run in your website url which url you have given in Application add time.

If you have any problem please ask me through the comment .



Using Facebook login in ASP.NET application

Step-1: Register site in Facebook:

  1. Open http://developers.facebook.com and login with your Facebook credentials after logging in you will get a screen like this:

  1. Click on "Build for Websites" link, you will reach to https://developers.facebook.com/docs/guides/web/ , just click on 'Apps' menu Items (the last menu Item from right side), you will reach to https://developers.facebook.com/apps. Click on  button, you will get following screen.

  1. Enter the name of your website in place of App Name, rest of the fields are optional so fill them if you require to use them and click on 'Continue' button. you will be asked to fill a captcha screen and then you will get the summary screen like below screenshot (Just masked the AppID).

  2. Give the URL of you website/ application Site URL text box of the app summery screen, like below screenshot. I have given localhost address as I will be testing the app from my local build, you will have to give your website URL in this.

Step-2: Create ASP.NET application using Facebook login:
  1. Open Visual Studio.
  2. Select File --> New --> Project/Solution --> 'ASP.NET Empty Application'
  3. Now Right Click on Project Name Select Add--> New Item from the pop-up menu and click on 'Web Form' to add Default.Aspx page. (See screenshot).

  4. Most of the code we will be doing on the HTML code of ASP.NET Page.
  5. For using Facebook login, we will have to use Facebook JavaScript SDK. There are three ways of using it:
    1. Load the JavaScript SDK asynchronously.<script>
                // Load the SDK Asynchronously
                (function (d) {
                    var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
                    if (d.getElementById(id)) { return; }
                    js = d.createElement('script'); js.id = id; js.async = true;
                    js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
                    ref.parentNode.insertBefore(js, ref);
                } (document));
            </script>
    2. Load the JavaScript SDK synchronously       <script src=https://connect.facebook.net/en_US/all.js type="text/javascript"></script>
    3. Download the SDK JavaScript file in your local project folder and use it from there. Implemented in 'Default.aspx' of solution.<script src="scripts/all.js" type="text/javascript"></script>
  6. We will also require jquery for initializing the library. so copy following code in header section of the page.<script
    src="scripts/jquery-1.8.0.min.js"
    type="text/javascript"></script> <script
    src="scripts/all.js"
    type="text/javascript"></script> 7) Now to initialize the Facebook SDK copy following code in a new script section :
             $("document").ready(function () {
                // Initialize the SDK upon load
                FB.init({
                    appId: 'YOUR_APP_ID', // App ID
                    channelUrl: '//' + window.location.hostname + '/channel', // Path to your Channel File
                    scope: 'id,name,gender,user_birthday,email', // This to get the user details back from Facebook
                    status: true, // check login status
                    cookie: true, // enable cookies to allow the server to access the session
                    xfbml: true  // parse XFBML
                });
                // listen for and handle auth.statusChange events
                FB.Event.subscribe('auth.statusChange', OnLogin);
            });
    Here YOUR_APP_ID will be the App Id you will get from the Facebook App.
  7. Also copy the following code after Above code in to get the response back and fill the values. // This method will be called after the user login into faceboookfunction OnLogin(response) {
                if (response.authResponse) {
                    FB.api('/me?fields=id,name,gender,email,birthday', LoadValues);                    
                }
            }
    
            //This method will load the values to the labels
            function LoadValues (me) {
                if (me.name) {
                    document.getElementById('displayname').innerHTML = me.name;
                    document.getElementById('FBId').innerHTML = me.id;
                    document.getElementById('DisplayEmail').innerHTML = me.email;
                    document.getElementById('Gender').innerHTML = me.gender;
                    document.getElementById('DOB').innerHTML = me.birthday;
                    document.getElementById('auth-loggedin').style.display = 'block';
                                }
            }
  8. Copy following code in the Body tag of the Page. <div id="fb-root"></div> <!-- This initializes the FB controls-->
        <div class="fb-login-button" autologoutlink="true" scope="user_birthday,email" >
          Login with Facebook
         </div> <!-- FB Login Button -->   
        <!-- Details --> 
        <div id="auth-status">    
        <div id="auth-loggedin" style="display: none">
            Hi, <span id="displayname"></span><br/>
            Your Facebook ID : <span id="FBId"></span><br/>
            Your Email : <span id="DisplayEmail"></span><br/>
            Your Sex:, <span id="Gender"></span><br/>
            Your Date of Birth :, <span id="DOB"></span><br/>        
        </div>
        </div>
  9. Your application is ready now, execute the application.

Comments

Popular posts from this blog

Convert HtmlToPDF in ASP.net & iTextshrap

Create Pivot Table In C#

How to Display Page Wise Total Amount & Grand Total Amount in Last page SSRS & RDLC Report