Giter Site home page Giter Site logo

247gradlabs / linkedinnet Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sparklenetworks/linkedinnet

28.0 1.0 15.0 3.23 MB

Sparkle.LinkedInNET will help you query the LinkedIn API with C# :)

Home Page: https://www.nuget.org/packages/Sparkle.LinkedInNET/

License: GNU Lesser General Public License v3.0

C# 95.23% CSS 0.29% Batchfile 0.35% HTML 4.11% ASP.NET 0.02%

linkedinnet's Introduction

LinkedInNET

Sparkle.LinkedInNET Nuget will help you query the LinkedIn API V2 :)

Motivation

Bring the .NET world a nice LinkedIn client library. + support V2 API.

Before you start - About LinkedIn API recent changes

By using the LinkedIn APIs you agree to the LinkedIn APIs Terms of Use.
This project is released under the LGPL v3 license.
This is NOT an official client library.

Update:

Api request tunneling are supported now.

Usage

1. Installation

Use it from Nuget.

Or build the sources... You have to create your own .snk file.

Supported frameworks: 4.5 (sync and task async).

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 key and secret. Get a LinkedIn API key.

// create a configuration object
var config = new LinkedInApiConfiguration("•api•key•••", "•api•secret•key••••••");

// 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.

var scope = AuthorizationScope.ReadBasicProfile | AuthorizationScope.ReadEmailAddress;
var state = Guid.NewGuid().ToString();
var redirectUrl = "http://mywebsite/LinkedIn/OAuth2";
var url = api.OAuth2.GetAuthorizationUrl(scope, state, redirectUrl);
// https://www.linkedin.com/uas/oauth2/authorization?response_type=code&client_id=...
// now redirect your user there

4. Get access token

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

// http://mywebsite/LinkedIn/OAuth2?code=...&state=...
public async Task<ActionResult> OAuth2(string code, string state, string error, string error_description)
{
    if (!string.IsNullOrEmpty(error) || !string.IsNullOrEmpty(error_description))
    {
        // handle error and error_description
    }
    else
    {
        var redirectUrl = "http://mywebsite/LinkedIn/OAuth2";
        var userToken = await api.OAuth2.GetAccessTokenAsync(code, redirectUrl);
        // keep this token for your API requests
    }

    // ...
}

You will find in the source codes a nicer way to build the redirect url.

var redirectUrl = this.Request.Compose() + this.Url.Action("OAuth2");

5. Example call: fetch user profile

var user = new UserAuthorization(userToken.AccessToken);
var profile = api.Profiles.GetMyProfile(user);

Yes, you have to pass the token for each call. This might seem redundant for some but we prefer stateless objects for multi-threaded contexts.

6. Errors

API error results throw LinkedInApiExceptions. You can find extra info in the Data collection.

try
{
    var profile = this.api.Profiles.GetMyProfile(user);
}
catch (LinkedInApiException ex) // one exception type to handle
{
    // ex.Message
    // ex.InnerException // WebException
    // ex.Data["ResponseStream"]
    // ex.Data["HttpStatusCode"]
    // ex.Data["Method"]
    // ex.Data["UrlPath"]
    // ex.Data["ResponseText"]
}
////catch (Exception ex) { } //  bad, don't do that

Library internal errors throw LinkedInNetExceptions. You should not catch them as they do not represent a normal behavior. This may be usefull when waiting for a fix.

You should not catch WebExceptions as they are wrapped into LinkedInApiExceptions.

Contribute

We welcome contributions. Especially if you can suggest/access/test methods with a partner API key.

We are generating code based on a XML file.
This XML file is manually filled to represent the API.
The API coverage should be implemented by modifying the XML file and enhancing code generation.

To generate the API code, build the "ServiceDefinition" project in Debug mode, edit LinkedInApiV2.xml, then use "Run custom tool" on the Service.tt file. The XML file will be read and most of the code will be updated automagically.

To alter code generation, search for CSharpGenerator.cs. Different methods are responsible of generating different parts of C# code (return types, api groups, selectors).

To add/alter API methods and return types, search for LinkedInApiV2.xml. This file describes the API in a human-readable and machine-readable way. Don't forget to re-generate the code (Service.tt).

References

https://docs.microsoft.com/en-us/linkedin/compliance/

.NET versions

Supported .NET Framework version:

  • .NET 4.5 (dependencies: Newtonsoft.Json ≥ 6.0.8, Microsoft.Net.Http ≥ 2.2.29)

We are using a lot of code generation so it won't be difficult to target any other framework.

Status

linkedinnet's People

Contributors

aclark09 avatar etodanik avatar evpxregu avatar gitter-badger avatar leventeolahx avatar maitlandmarshall avatar marinarukavitsyna avatar pschaefer2305 avatar sandrock avatar tazacban avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.