Search code examples
c#oauthlinkedin-api

How do I store the LinkedIn API AccessToken so I don't have to re-enter credentials every time I use the LinkedIn API?


I am writing an app to mine information from LinkedIn. I've only found one code sample thus far on oAuth. I'm having trouble understanding the workflow of oAuth, for example:

  1. The Example asks for the Username/Password combination to log into LinkedIn and return a token, but in my case, I will always use the same LinkedIn Account.

Since I'm always going to be using the same user to access the LinkedIn API, is there a way to do it so I don't have to re-enter the user name and password for every access request? The facebook API allows me to set the Token to not expire, thereby allowing me to save this token as an Attribute inside my application).

The idea is :

  1. Get a token for a certain LinkedIn Account
  2. Store it in my app hardcoded, since this is the only account I will be using the retrieve information from LinkedIn.
  3. Make API Calls using this token, everytime I need it
  4. Parse the JSON/XML file

How do I do this in C#?


Solution

  • You first need to determine the member token, and the corresponding OAuth token -- you could do this as a one off, and LinkedIn have some quite good documentation about authorizing (along with links to tools to verify, and to libraries that you can use to simplyify matters)

    Once you have those, it's just a case of storing them "somewhere safe" - there is even a clause in the LinkedIn APIs Terms of Use that permits storage:

    You may store the Member Token and the OAuth Token until the earlier of:

    • Your ceasing using the APIs;
    • The LinkedIn user uninstalls your application or directs you to delete the user's information; or,
    • We terminate your use of them for breach of these Terms.