Linkedin Lead Generation: A Few Hacks

LinkedIn is a powerful tool to develop professional relationships. Using its tools you can also increase your marketing efficiency.

Linkedin Lead Generation: A Few Hacks


In this article, I will explain how to retrieve all possible information from a LinkedIn Account on an ASP.Net website using C#. I will be also

explaining how to create a LinkedIn Application and get the LinkedIn API Key and Secret Key on LinkedIn Developers Site.

Getting Started with the LinkedIn Lead Generation


Fetch LinkedIn API Key and Secret Key on LinkedIn Developers Site

Step 1 :


To create an application, you need to visit the LinkedIn Developer site using the following URL
https://www.linkedin.com/secure/developer

Step 2 :


Click on Create Application button.

Step 3 :


After that, you need to fill the following form

After filling the form, click on Submit

Step 4 :



Once you have created a New Application,you will find a new form inside which is the most important section - Default Application Permission . Here you

need to choose what user details you want to fetch through your application and also need to add Authorized Redirect URLs. Once the form is submitted, you will get the Client ID and Client Secret Key as shown below.

LinkedIn Authorization and Fetching the LinkedIn User Profile Details

The very first thing you need to do is set the LinkedIn Client ID and Client Secret Key to its respective properties.

Inside the Button click event handler, the Authorize method is called which will redirect a user to the LinkedIn Website where he/she can login and also

grant permissions to the application to fetch his profile details.

Once the user has authorized the LinkedIn profile, the details are fetched using the Fetch method as a dataset object and are displayed on the page using Image

and Label controls

Sparkle.LinkedInNET will help you query the LinkedIn API

1. Installation


Via NuGet

 PM> Install-Package Sparkle.LinkedInNET


2. Create API client with configuration


The LinkedInApi class is the entry point for all API calls. You must instantiate it with a configuration object. The minimum configuration is the API keycand secret.

// create from config file





















Get a LinkedIn API key.


// create from config file
var config = LinkedInApiConfiguration.FromAppSettings("LogiDemo.LinkedInConnect");
// get the APIs client
var api = new LinkedInApi(config);


3. Create OAuth2 authorize url



The OAuth2 authentication process is fully supported. The GetAuthorizationUrl method will generate the OAuth2 url to navigate the user to.



protected void Page_Load(object sender, EventArgs e)
{
// create from config file
var config = LinkedInApiConfiguration.FromAppSettings("LogiDemo.LinkedInConnect");
// or manually
// var config = LinkedInApiConfiguration("api key", "api secret key");

// get the APIs client

var api = new LinkedInApi(config);

var scope = AuthorizationScope.ReadBasicProfile | AuthorizationScope.ReadEmailAddress;
var state = Guid.NewGuid().ToString();
var redirectUrl = "http://localhost:49965/WebForm1.aspx";

var url = api.OAuth2.GetAuthorizationUrl(scope, state, redirectUrl);
Response.Redirect(url.OriginalString);
}



4. Get the access token


When the user is redirected back to your website, you can get an access code.


if (Request.QueryString["code"] != null)

{

var accessCode = Request.QueryString["code"]; // save this code for each user in db and use this code for

// further accessing

var redirectUrl = "http://localhost:49965/WebForm1.aspx";


// this section of code is using to access the web

var config = LinkedInApiConfiguration.FromAppSettings("LogiDemo.LinkedInConnect");

var api = new LinkedInApi(config);

var userToken = api.OAuth2.GetAccessToken(accessCode, redirectUrl);
}


5. Example call: fetch user profile


var userToken = api.OAuth2.GetAccessToken(accessCode, redirectUrl);
var profile = api.Profiles.GetMyProfile(user, acceptLanguages, fields);


6. Field selectors


The API uses field lists to fetch the desired data. Simple extension methods will
allow you to make strongly-typed field selection.


var user = new UserAuthorization(userToken.AccessToken);

string culture = "en-US";

var acceptLanguages = new string[] { culture ?? "en-US", "fr-FR", };

var fields = FieldSelector.For()

.WithId()

.WithFirstName()

.WithLastName()

.WithFormattedName()

.WithEmailAddress()

.WithHeadline()

.WithLocationName()

.WithLocationCountryCode()


.WithPictureUrl()

.WithPublicProfileUrl()

.WithSummary()

.WithIndustry()

.WithPositions()

.WithPositionsSummary()

.WithThreeCurrentPositions()

.WithThreePastPositions()

.WithProposalComments()

.WithAssociations()

.WithInterests()

.WithLanguageId()

.WithLanguageName()

.WithLanguageProficiency()

.WithCertifications()

.WithEducations()

.WithFullVolunteer()

.WithPatents()

.WithRecommendationsReceivedWithAdditionalRecommenderInfo()

.WithDateOfBirth()

.WithPhoneNumbers()

.WithImAccounts()

.WithPrimaryTwitterAccount()

.WithTwitterAccounts()

.WithSkills();

var profile = api.Profiles.GetMyProfile(user, acceptLanguages, fields);
var firstName = profile.Firstname;

var lastName = profile.Lastname;

var emailAddress = profile.EmailAddress;

var headine = profile.Headline;

var location = profile.Location.Name;

var industry = profile.Industry;

var dateOfDirth = profile.DateOfBirth;
}

You can create your own extension methods when you desire many fields. Check the source code to see how it works Download Source Code.


Conclusion


I hope by following the steps mentioned above , you can easily retrieve all possible information about a LinkedIn Account



Leave a Reply

Your email address will not be published.


Comment


Name

Email

Url



    Get Free Consultation
    From Our Experts !