Linkedin oAuth desktop c# sample embedded webBrowser

I’ve created and uploaded some sample code for using Linkedin’s oauth library in a c# desktop app.  Faith Yasar’s c# code was my starting point.  A bit of a refactor of the oAuth librarie to include the oauth_callback parameter was needed, as well as code for displaying the login dialog.

Code can be found here in a forum post I made on linkedin.

The code contained includes a test harness as well as the oauth libraries for oauth login dance and Linkein API requests.  Oauth login is handled with an embedded webBrowser which is shown modally for the user to login.  Upon login completion, dialog will be closed and the token and verifier will be available from the dialogs property.

To use the code, simply Add your Linkedin consumer secret and Consumer key to the OauthLinkedIn.cs file:

private string _consumerKey = "ENTER_YOUR_CONSUMER_KEY";
private string _consumerSecret = "ENTER_YOUR_CONSUMER_SCRET";

Then you can make api calls following a few steps:

OAuthLinkedIn _oauth = new OAuthLinkedIn();
String requestToken = _oauth.getRequestToken();
_oauth.authorizeToken();
String accessToken = _oauth.getAccessToken();</div>

Hope that helps

15 thoughts on “Linkedin oAuth desktop c# sample embedded webBrowser

  1. Hi,
    Your code is amazing. I am a student at University of Southern California, LA. I am currently pursuing an academic project where we use data from LinkedIn. Can I use snippets of your code and cite your work?

    Thanks
    S

  2. Hi David,
    Thanks a lot for this code. I’ve just got into the LinkedIn API and didn’t really know where to start. Your code was most useful. Thanks!

  3. Hi – I entered my consumer key/secret in the file, but when I click on “Login”, I get “Remote server returned an error: (400) Bad Request”.
    Could it be related to the ‘Application Details’ section of the LinkedIn page? For example, I put App type as “Desktop” and Integration Url as “http://localhost/”.
    Thanks for any help

  4. Hi David,
    thank you for the code. However, one thing is not clear to me:
    The upper 4 lines of code are used the first time we want to login to linkedin – if the user allows us permanent access then the next time we don’t have to show the login dialog again, right?

    How do we use this code then?
    I tried:

    OAuthLinkedIn linkedIn= new OAuthLinkedIn();
    String requestToken = linkedIn.getRequestToken();
    linkedIn.Token = token;
    linkedIn.Verifier = verifier;
    linkedIn.getAccessToken();

    where token and verifier are variables that I saved after successfully logging in the first time (when we called linkedIn.authorizeToken()). This however doesn’t work (I get 401 error).

    How should I do it then?
    Thanks in advance for your help!!
    Gregor

  5. Hi David,
    Thank you for this clear and elegant code. I have been finding aspects of OAuth to be confusing and your classes made it understandable. I owe you a big debt of gratitude. If you’re ever in Ottawa and feel so inclined, I would be happy to take you for a nice dinner!
    Best regards, your friend from the east, Ward

  6. Hi David,
    Thanks lot. Nice piece of code you have done.
    I am developing a web application which helps to find people. If the user entered name “John” then he clicks the button.
    After clicks the button, I need to get people count who are having name “John” and need to display it in my web page.
    For this, I have used oAuth. If I use this, I need to go linkedIn page to obtain oauth_verifier. After that only, i can get people count. But, what I want is, I don’t need to go linked In page to get oauth_verifier. Instead of that, simply i click the button and display the result in the same page.

    for an example: http://www.pagesjaunes.fr/pagesblanches
    if you go through this link, they will show up the people count without navigating to linked In web page.

    How do they do it?

    thanks
    r.eswaran.

  7. I am working on a desktop app. After I login I need to allow ” Grant Service Application access” ( press button continue).
    Could you tell me how can I skip this? Why do I need to allow ( click on ”continue” button every time I login). Could you give me am example how to do that?

    Also the logout method
    textbox.text= _oauth.APIWebRequest(“GET”, “https://www.linkedin.com/secure/login?session_full_logout=&trk=hb_signout”, null); gives me something in xml….but when I press again login, it is still my account. How can I make logout function?

    Thanks,
    Sincerelly,
    Mary

  8. Hey boss,

    Thank you for your hard work, you’ve managed to trim it down a little and make it easier to read.

    I’ve posted a 401 error question on linkedIn and you’re code is mixed with Fatih, so I am hoping that one of you can give me a pointer.

    Do you have any idea to adjustments that i can make to your code to stop this 401 error from happening with retrieving data from the profile? I am able to make it all the way to requesting data and it breaks. I know it is something simple but right now it seems like a giant… 😉

    https://developers.linkedin.com/thread/1190?page=2#comment-19373

    HELP………………

  9. Hi David,
    Appreciate your work a lot! Thanks so much.
    I have a question. How can I regenerate the access token and token secret for a user automatically without getting the user to authorize himself to the application again.Looking forward to your reply.Thanks a ton!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s