Michele, I have the germ of something that works.
Your code outline was pretty close...
In a controller function...
auth.settings.login_form =
LinkedInAccount(globals(),CLIENT_ID,CLIENT_SECRET, AUTH_URL,
TOKEN_URL, ACCESS_TOKEN_URL)
token = auth.settings.login_form.accessToken()
if token is None:
# add handling
pass
else:
from gluon.contrib.login_methods.linkedin import LinkedIn
api = LinkedIn(CLIENT_ID, CLIENT_SECRET, 'http://
afterthefact.org/')
api.access_token = token.key
api.access_token_secret = token.secret
# free to call methods of LinkedIn class. E.g., GetProfile()
profile = api.GetProfile()
Seemingly a little ugly but a self-written class 'LinkedInAccount'
derived from OAuthAccount can be married with Özgür Vatansever's
LinkedIn class. The former authenticates with LinkedIn and the latter
retrieves most of the data.
thanks M for the pointer
On Nov 16, 10:20 am, Carl <[email protected]> wrote:
> ah ha!
>
> I do have a class based on OAuthAccount working but it never occurred
> to me to build 'sideways' and plug LinkedIn into my solution.
>
> I'll give it a go. thanks for responding.
>
> On Nov 15, 9:52 pm, Michele Comitini <[email protected]>
> wrote:
>
>
>
>
>
>
>
> > Never tested, just a suggestion write something similar in your model
> > (see:http://code.google.com/r/michelecomitini-facebookaccess/source/browse...
>
> > class LinkedinTest(OAuthAccount):
> > def get_user(self):
> > if self.accessToken() is not None:
> > client = oauth.Client(self.consumer, self.accessToken())
> > resp, content =
> > client.request('https://api.linkedin.com/v1/people/~:(id,first-name,last-name)')
> > if resp['status'] != '200':
> > # cannot get user info. should check status
> > return None
> > x = dom.parseString(content)
> > firstname =
> > x.getElementsByTagName('first-name')[0].firstChild.data
> > username = firstname + ' '
> > +x.getElementsByTagName('last-name')[0].firstChild.data
> > uid = x.getElementsByTagName('id')[0].firstChild.data
> > return dict(username=username, name=firstname,
> > registration_id=uid)
>
> > auth.settings.login_form=LinkedinTest(globals(),CLIENT_ID,CLIENT_SECRET,
> > AUTH_URL, TOKEN_URL, ACCESS_TOKEN_URL)
>
> > api = LinkedIn(api_key, api_secret, callback_url)
>
> > api.access_token=auth.settings.login_form.accessToken()
>
> > now you should be able to use the linkedin api, skipping the OAuth
> > code embedded into it.
>
> > 2010/11/15 Carl <[email protected]>:
>
> > > Has anyone got gluon/contrib/login_methods/linked_account.py working?
>
> > > I've built directly upon /gluon/contrib/login_methods/
> > > oauth10a_account.py with my own specific LinkedIn code but having
> > > foundhttp://code.google.com/p/python-linkedin/Iwanted to use this
> > > to avoid reinventing the wheel (Özgür Vatansever's linkedin.py looks
> > > clean and has broad support for LinkedIn's API).
>
> > > But, linkedin.py doesn't look finished; for example:
> > > (from web2py 1.89.1)
>
> > > Line 43.
> > > result = self.request.vars.verifier
>
> > > The vars variable sets 'oauth_verifier' on returning from the LinkedIn
> > > website but not 'verifier'.
>
> > > Anyone tread this path?