jsOAuth with linkedin

172 views
Skip to first unread message

Irfan Cütcü

unread,
Jun 24, 2012, 6:28:09 PM6/24/12
to jsOAuth
How do I implement jsOAuth with linkedin? I have problems getting an
access-token. Did anyone try this? It should be without pin. The
Twitter-example is working fine. but not with linkedin.

Rob Griffiths

unread,
Jun 25, 2012, 12:16:26 AM6/25/12
to jso...@googlegroups.com
Looking at the documentation it should be as straight forward as the twitter example. Make sure your urls use https as any redirects will break the signing process

Irfan Cütcü

unread,
Jun 25, 2012, 6:17:39 AM6/25/12
to jsOAuth
Thank you for your reply! I really need help on this. Trying to solve
it since a couple of days.

I tried to use it the same way and I am using https, but it does not
work.

Calling the Authorization works pretty well:

oauth.get('https://api.linkedin.com/uas/oauth/requestToken',
function(data) {
requestParams = data.text;
$('#oauthStatus').html('<span style="color:blue;">Getting
authorization...</span>');
alert(requestParams);
window.plugins.childBrowser.showWebPage('https://
www.linkedin.com/uas/oauth/authorize?'+data.text,
{ showLocationBar : false });
},
function(data) {
alert('Error : No Authorization');
$('#oauthStatus').html('<span style="color:red;">Error
during authorization 2</span>');
}
);

When the childbrowser is changing the location the the parameters are
extracted using this

var index, verifier = '';
var params = loc.substr(loc.indexOf('?') + 1);

params = params.split('&');
for (var i = 0; i < params.length; i++) {
var y = params[i].split('=');
if(y[0] === 'oauth_verifier') {
verifier = y[1];
}
}

After having the verifier I am trying to get the access Token like
this:

oauth.get('https://api.linkedin.com/uas/oauth/
accessToken?oauth_verifier='+verifier+'&'+requestParams,
function(data) {
var accessParams = {};
var qvars_tmp = data.text.split('&');
for (var i = 0; i < qvars_tmp.length; i++)
{
var y = qvars_tmp[i].split('=');
accessParams[y[0]] =
decodeURIComponent(y[1]);
}
//alert('AppLaudLog: ' +
accessParams.oauth_token + ' : ' + accessParams.oauth_token_secret);
$('#oauthStatus').html('<span
style="color:green;">Success!</span>');

oauth.setAccessToken([accessParams.oauth_token,
accessParams.oauth_token_secret]);

// Save access token/key in localStorage
var accessData = {};
accessData.accessTokenKey =
accessParams.oauth_token;
accessData.accessTokenSecret =
accessParams.oauth_token_secret;
console.log("AppLaudLog: Storing token key/
secret in localStorage");
localStorage.setItem(localStoreKey,
JSON.stringify(accessData));

// alert("Now lets use the api with our
accesstoken");

window.plugins.childBrowser.close();
},
function(data) {
alert('Error : No Authorization');
alert("AppLaudLog: 1 Error " + data);
$('#oauthStatus').html('<span
style="color:red;">Error during authorization - After SignIn</span>');
}
);

Twitter is working fine, but linkedin not! If you take a look at these
slides, everything is going right till slide 18:
http://www.slideshare.net/episod/linkedin-oauth-zero-to-hero

Thank you in advance for any help.

Irfan


On 25 Jun., 06:16, Rob Griffiths <r...@bytespider.eu> wrote:
> Looking at the documentation it should be as straight forward as the twitter example. Make sure your urls use https as any redirects will break the signing process
>

Rob Griffiths

unread,
Jun 25, 2012, 6:25:52 AM6/25/12
to jso...@googlegroups.com
You need to call oauth.setVerifier(verifier);

Also you can save yourself a lot of effort and use fetchRequestToken and fetchAccessToken as demonstrated in the following example

Clearly it will need to be adapted to use the callback and child browser code you showed me.

Documentation can be found here.


Rob

-- 
Rob Griffiths
Sent with Sparrow

Irfan Cütcü

unread,
Jun 25, 2012, 4:31:47 PM6/25/12
to jsOAuth
Hey Rob,

that relly helped me, but now I have a strange after having authorized
to the app.

After authorizing the app API calls work perfect. But if I close and
reopen the app, I get an error after calling the authorization again:
"Cannot find the authorization-token". After clearing the cahce it
works again. Are there any paremters saved in the cache that make that
error???

Irfan

On 25 Jun., 12:25, Rob Griffiths <r...@bytespider.eu> wrote:
> You need to call oauth.setVerifier(verifier);
>
> Also you can save yourself a lot of effort and use fetchRequestToken and fetchAccessToken as demonstrated in the following example
>
> https://gist.github.com/1071227
> Clearly it will need to be adapted to use the callback and child browser code you showed me.
>
> Documentation can be found here.http://bytespider.github.com/jsOAuth/api-reference/
>
> Rob
>
> --
> Rob Griffiths
> Sent with Sparrow (http://www.sparrowmailapp.com/?sig)
>
>
>
>
>
>
>
> On Monday, 25 June 2012 at 11:17, Irfan Cütcü wrote:
> > Thank you for your reply! I really need help on this. Trying to solve
> > it since a couple of days.
>
> > I tried to use it the same way and I am using https, but it does not
> > work.
>
> > Calling the Authorization works pretty well:
>
> > oauth.get('https://api.linkedin.com/uas/oauth/requestToken',
> > function(data) {
> > requestParams = data.text;
> > $('#oauthStatus').html('<span style="color:blue;">Getting
> > authorization...</span>');
> > alert(requestParams);
> > window.plugins.childBrowser.showWebPage('https://
> >www.linkedin.com/uas/oauth/authorize?'+data.text(http://www.linkedin.com/uas/oauth/authorize?'+data.text),
> > On 25 Jun., 06:16, Rob Griffiths <r...@bytespider.eu (http://bytespider.eu)> wrote:
> > > Looking at the documentation it should be as straight forward as the twitter example. Make sure your urls use https as any redirects will break the signing process
>

Rob Griffiths

unread,
Jun 25, 2012, 4:41:33 PM6/25/12
to jso...@googlegroups.com
Well usually I'd save to some sort of local db and reload the tokens, perhaps you need todo the same?

Irfan Cütcü

unread,
Jun 25, 2012, 5:21:58 PM6/25/12
to jsOAuth
That made me read this document again:
https://docs.google.com/viewer?pid=sites&srcid=ZGVmYXVsdGRvbWFpbnxtb2JpbGVkZXZlbG9wZXJzb2x1dGlvbnN8Z3g6N2E5MTMxZTUzMGQ0YTM5Yw&docid=8e8baee1ddf6b720a170ad5d2280d4d7%7Cff2edf1d406e18d8519e0a2ba1262bef&chan=EQAAAD6vGmC44Z2shMwx%2B1Ay%2BCiLYt88h8yB7MTFpbZj80UP&a=v&rel=zip;z3;main.js

It really helped me. Now I save the access key to the localstorage.
When calling the auhtorization it first checks if any accessToken is
saved to the localstorage. If not it calls the authorization. If it is
saved it makes an api call to check if it is still valid. If not it
redirects again to authorize again.

Thank you Rob. I really appreciate it.

On 25 Jun., 22:41, Rob Griffiths <r...@bytespider.eu> wrote:
> Well usually I'd save to some sort of local db and reload the tokens, perhaps you need todo the same?
>
> >>>www.linkedin.com/uas/oauth/authorize?'+data.text(http://www.linkedin....),
Reply all
Reply to author
Forward
0 new messages