0

We've undertaken a new project of posting Jobs directly to LinkedIn using Job Posting API from within our web application. Our web application is developed in Java.

In order to post jobs, LinkedIn uses OAuth signed calls. OAuth-based authentication is very new for me. There is sample code available in LinkedIn Developers for posting of Jobs in C# here. But unfortunately, I couldn't find equivalent sample code for Java.

Any pointers/example code in posting of Jobs to LinkedIn written in Java are greatly appreciated.

Gnanam
  • 10,613
  • 19
  • 54
  • 72
  • 1
    I've written a java library that follows the full OAuth 1, you'll just have to provide the request token URL and authorization URL for LinkedIn and you'll be good to go. :) [JOAuth](http://code.google.com/p/joauth/) – Buhake Sindi Jun 09 '11 at 12:33
  • Why it's been down voted here? – Gnanam Jun 09 '11 at 12:53
  • Likely because it is "not really" Java specific. If you have a C# example you should be able to just rewrite it ... – Angel O'Sphere Jun 09 '11 at 13:13
  • @Angel: But I don't think we can just rewrite in this case. You'll understand this if you check the sample code given for C# in above link. – Gnanam Jun 09 '11 at 14:17
  • @TheEliteGentleman: But JOAuth is based on 3-legged authentication, but LinkedIn posting of Jobs uses 2-legged authentication. Any idea? – Gnanam Jun 10 '11 at 05:14
  • @Gnaman, what do you mean? LinkedIn uses [OAuth 1](http://developer.linkedin.com/docs/DOC-1245) and it's the same JOAuth supports it. 2 legged goes with OAuth 2. – Buhake Sindi Jun 10 '11 at 05:30
  • @TheEliteGentleman: Can you check this - [Using OAuth with the JobsAPI](http://developer.linkedin.com/docs/DOC-1298)? Also, using JOAuth how do I POST Job XML data? – Gnanam Jun 10 '11 at 05:40
  • Using JOAuth, you will have to get an Access Token (using the LinkedIn OAuth process). After this, you can now create an HTTP-Authorization header and do an HTTP request to linked in Jobs REST call. – Buhake Sindi Jun 10 '11 at 06:02
  • @TheEliteGentleman: This is just for my clarification. Getting an Access Token and then signing request is a 3-legged OAuth, am I right? For 2-legged OAuth call, just consumer key and consumer secret is sufficient to make HTTP request. Am I right in my understanding? – Gnanam Jun 10 '11 at 06:34
  • 1
    No, 3-Legged OAuth requires you to get a 1) request token, then 2) authorized request token then 3) access token. 2-legged OAuth requires you to get 1) request token and then 2) access token. After all, you need an access Token to do API calls. – Buhake Sindi Jun 10 '11 at 06:45
  • @TheEliteGentleman: Let me know whether I've understood this correctly. In 2-legged OAuth, to get Access Token, `Verifier` (which actually directs to an URL, user clicks 'Authorize' and gets the security code) is not required, am I right? – Gnanam Jun 10 '11 at 08:05
  • @Gnanam, read the OAuth 2 specification to understand how it works and you'll see that it's 2 step process. You're confusing OAuth 1 which is always a 3-Legged Authorization with a 2-Legged Authorization. – Buhake Sindi Jun 10 '11 at 08:23
  • @TheEliteGentleman: In the code example given for connecting to Facebook Graph API, what is `parameters.setCode("3f61aa47b915215a938d2722-682316653|5OPOkmKew_W8vybb9sccIPoivAg.")`? How do I get this code in my case? I've API Key and Secret Key for LinkedIn. – Gnanam Jun 14 '11 at 05:10
  • @Gnanam, that's the 2-Legged OAuth 2 to retrieve Access Token. The `setCode()` method is a request token Facebook returned from requesting it. – Buhake Sindi Jun 14 '11 at 05:36
  • @TheEliteGentleman: Thanks. Similarly, what is `client_id` and `client_secret`? Where do I pass my API Key and Secret Key supplied by LinkedIn? – Gnanam Jun 14 '11 at 06:24
  • @Gnanam, Did you read the code `OAuth2Consumer consumer = new OAuth2Consumer(client_id, client_secret, provider);`? – Buhake Sindi Jun 14 '11 at 06:40
  • @TheEliteGentleman: So, `client_id` is my API Key and `client_secret` is my Secret Key, am I right? – Gnanam Jun 14 '11 at 06:46
  • @TheEliteGentleman: Now, how do I get Request Token to pass it to `setCode()` method? I don't find any statement? – Gnanam Jun 14 '11 at 06:54
  • @Gnanam, Are you using OAuth 1 or OAuth 2? Also, I suggest creating a new question if you have problems. – Buhake Sindi Jun 14 '11 at 06:56
  • @TheEliteGentleman: I've created a new question - [Using JOAuth library to post jobs in LinkedIn](http://stackoverflow.com/q/6340298/181870) – Gnanam Jun 14 '11 at 07:22
  • This needs to be a two-legged OAuth 1.0a call. – Adam Trachtenberg Jun 14 '11 at 07:23

1 Answers1

0

Before you get too far, I want to make sure that you know that the Job Posting API is a closed program that requires you to contact LinkedIn, meet certain criteria, and sign an API amendment.

http://developer.linkedin.com/community/jobs

Assuming you are good there, here is sample code showing how to make LinkedIn API calls in Java using Scribe. You should be able to take that along with the C# code and get what you need without too much difficulty.

http://developer.linkedin.com/message/4568#4568

Adam Trachtenberg
  • 2,231
  • 1
  • 14
  • 18
  • @Adam: Yes, I knew that Job Posting API is a closed program and I've signed-up for API Developer Key. I've both API Key and Secret Key. Let me read the link given by you... – Gnanam Jun 10 '11 at 07:07
  • @Adam: I read [LinkedIn OAuth with Java](http://developer.linkedin.com/message/4568#4568). In `5th Step: Get the Access Token`, how do I get the verifier step done programmatically in Java; otherwise every time I need to invoke the browser manually to get the 5-digit security code. – Gnanam Jun 10 '11 at 07:16
  • @Adam: Also, since this is a Job Posting, how do I POST Job XML data in the Request in the above article? Posting of XML data is not given here. – Gnanam Jun 10 '11 at 07:31
  • @Gnanam: After you do the flow once, you can store the tokens until they expire (which can be set to Never). But you will always need a human to sign into their account for each account you need. – Adam Trachtenberg Jun 10 '11 at 20:04
  • 1
    @Gnanam: Try and do some searching... I Googled and found: `final OAuthRequest request = new OAuthRequest(Verb.POST, url);` `request.addHeader("Content-Length", Integer.toString(load.length()));` `request.addHeader("Content-Type", "text/xml"); request.addPayload(load);` `this.service.signRequest(this.accessToken, request);` – Adam Trachtenberg Jun 10 '11 at 20:05
  • @Gnanam: Last, just because you have key, doesn't mean you can POST jobs. You need business approval and then we need to modify the key to make the request successful. – Adam Trachtenberg Jun 10 '11 at 20:09
  • @Adam: I just gone thro' the C# code sample given [Code Sample: Posting a Job in C#](http://developer.linkedin.com/docs/DOC-1300), I could see that there is `no exchange of Request Token for Access Token` happening. I even took a look at both _oAuthLinkedIn.cs_ and _oAuthBase2.cs_. All what I can infer from the code is that a signature is generated using consumer key, consumer secret, etc. and is passed to `oauth_signature` and `oauth_signature_method` is set to `HMAC-SHA1`. How do I implement the same in Java? – Gnanam Jun 13 '11 at 13:38
  • These are two-legged OAuth calls, you so don't need to do the dance, but just generate the signature. If you don't know OAuth 1.0a, you will need to start a new question on that, as it's beyond the scope of this one. – Adam Trachtenberg Jun 14 '11 at 07:22
  • 2
    your 2nd link not working no page found msg display do some needful – Jubin Patel May 30 '13 at 05:21