Skip to content
This repository was archived by the owner on Nov 3, 2020. It is now read-only.

Commit a75f291

Browse files
committed
Fixed Linkedin integration
1 parent 0efc285 commit a75f291

File tree

6 files changed

+52
-22
lines changed

6 files changed

+52
-22
lines changed

README.md

+12-7
Original file line numberDiff line numberDiff line change
@@ -349,17 +349,22 @@ If you want to turn off Flickr integration just set `FLICKR_INTEGRATION_ENABLED`
349349

350350
### Setting up LinkedIn integration
351351

352-
LinkedIn has another level of security, therefore we need more information instead of just an api_key like Tumblr. To get started create a new application on LinkedIn for your website by going to <https://developer.linkedin.com/>. Once you are done creating your application you will be taken to your application page on LinkedIn, there you already have four pieces of the puzzle, the `Consumer key`, `Consumer secret`, `User Token` and `User Secret` make sure you save those.
352+
LinkedIn has the same level of security as Instagram and Foursquare and similar steps on getting the access token ourselves. To get started create a new application on LinkedIn for your website by going to <https://developer.linkedin.com/>. Once you are done creating your application you will be taken to your application page on LinkedIn, there you already have a few pieces of the puzzle, the `Api Key`, `Secret Key`, make sure you save those.
353353

354-
Once you have those four items from LinkedIn you have to enter them in your **syte_settings.py** located in `syte > syte_settings.py`. Once you open that file enter the following:
354+
In that same page make sure to enter `http://127.0.0.1:8000/linkedin/auth/` under Oauth 2.0 Redirect URls.
355355

356-
* `Consumer key` string you saved under `LINKEDIN_CONSUMER_KEY`
357-
* `Consumer secret` string you saved under `LINKEDIN_CONSUMER_SECRET`
358-
* `User token` string you saved under `LINKEDIN_USER_TOKEN`
359-
* `User secret` string you saved under `LINKEDIN_USER_SECRET`
356+
Once you have those items from LinkedIn you have to enter them in your **syte_settings.py** located in `syte > syte_settings.py`. Once you open that file enter the following:
360357

361-
If you want to turn off the LinkedIn integration just set `LINKEDIN_INTEGRATION_ENABLED` to False.
358+
* `Consumer key` string you saved under `LINKEDIN_API_KEY`
359+
* `Consumer secret` string you saved under `LINKEDIN_API_SECRET`
360+
361+
After you have entered those two items, follow the steps below for running your Syte locally on your machine. Once you have your Syte running navigate to `http://127.0.0.1:8000/linkedin/auth`, you will be taken to Linkedin's website and will be asked to sign in and authorize your application. After you authorized your application you will be taken back to your Syte and you will be given your ***Access Token***.
362+
363+
Once you have the access token from Foursquare you have to enter them in your **syte_settings.py** located in `syte > syte_settings.py`. Once you open that file enter the following:
364+
365+
* ***Access Token*** under `LINKEDIN_TOKEN`
362366

367+
If you want to turn off the LinkedIn integration just set `LINKEDIN_INTEGRATION_ENABLED` to False.
363368

364369

365370
## Running & Deployment Instructions

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Django==1.5.2
2-
requests==1.2.3
2+
requests==2.3.0
33
wsgiref==0.1.2
44
gunicorn==0.16.1
55
pybars==0.0.4
66
python-twitter==1.0
7-
python-linkedin==4.0
7+
python-linkedin==4.1
88
dj-static==0.0.5

syte/syte_settings.py

+3-4
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,9 @@
132132

133133
#LinkedIn Integration
134134
LINKEDIN_INTEGRATION_ENABLED = True
135-
LINKEDIN_CONSUMER_KEY = '[ENTER YOUR LINKEDIN CONSUMER KEY HERE]'
136-
LINKEDIN_CONSUMER_SECRET = '[ENTER YOUR LINKEDIN CONSUMER SECRET KEY HERE]'
137-
LINKEDIN_USER_TOKEN = '[ENTER YOUR LINKED IN USER TOKEN HERE]'
138-
LINKEDIN_USER_SECRET = '[ENTER YOUR LINKED IN USER SECRET HERE]'
135+
LINKEDIN_API_KEY = '[ENTER YOUR LINKEDIN CONSUMER KEY HERE]'
136+
LINKEDIN_API_SECRET = '[ENTER YOUR LINKEDIN CONSUMER SECRET KEY HERE]'
137+
LINKEDIN_TOKEN = '[ENTER YOUR LINKED IN USER TOKEN HERE]'
139138

140139
SITEMAP_ENABLED = False
141140

syte/templates/linkedin_auth.html

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% extends 'base.html' %}
2+
{% block pagetitle %}Linkedin Auth{% endblock %}
3+
{% block main_section %}
4+
<section class="main-section">
5+
<article>
6+
<h2>Linkedin Access Token</h2>
7+
<p>Go to your syte_settings.py and enter the token under <code>LINKEDIN_TOKEN</code>.</p>
8+
<dl>
9+
<dt>Access Token</dt><dd>{{ token }}</dd>
10+
</dl>
11+
</article>
12+
</section>
13+
{% endblock %}
14+
15+

syte/urls.py

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
#Linkedin Integration
9595
if settings.LINKEDIN_INTEGRATION_ENABLED:
9696
urlpatterns += patterns('',
97+
url(r'^linkedin/auth/?$', 'syte.views.linkedin_view.linkedin_auth'),
9798
url(r'^linkedin/?$', 'syte.views.linkedin_view.linkedin_view'),
9899
)
99100

syte/views/linkedin_view.py

+19-9
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,30 @@
44

55
from django.http import HttpResponse
66
from django.conf import settings
7+
from django.shortcuts import redirect, render
78

89
LINKEDIN_NETWORK_UPDATE_TYPES = linkedin.NETWORK_UPDATES.enums.values()
910

10-
def linkedin_view(request):
11-
authentication = linkedin.LinkedInDeveloperAuthentication(
12-
consumer_key=settings.LINKEDIN_CONSUMER_KEY,
13-
consumer_secret=settings.LINKEDIN_CONSUMER_SECRET,
14-
user_token=settings.LINKEDIN_USER_TOKEN,
15-
user_secret=settings.LINKEDIN_USER_SECRET,
16-
redirect_uri=settings.SITE_ROOT_URI,
17-
permissions=linkedin.PERMISSIONS.enums.values()
11+
def linkedin_auth(request):
12+
code = request.GET.get('code', None)
13+
14+
authentication = linkedin.LinkedInAuthentication(
15+
settings.LINKEDIN_API_KEY,
16+
settings.LINKEDIN_API_SECRET,
17+
'{0}linkedin/auth/'.format(settings.SITE_ROOT_URI),
18+
linkedin.PERMISSIONS.enums.values()
1819
)
1920

20-
application = linkedin.LinkedInApplication(authentication)
21+
if not code:
22+
return redirect(authentication.authorization_url)
23+
24+
if code:
25+
authentication.authorization_code = code
26+
token = authentication.get_access_token()
27+
return render(request, 'linkedin_auth.html', {'token': token[0]})
28+
29+
def linkedin_view(request):
30+
application = linkedin.LinkedInApplication(token=settings.LINKEDIN_TOKEN)
2131
profile_data = application.get_profile(selectors=['id', 'first-name', 'last-name', 'headline', 'location',
2232
'num-connections', 'skills', 'educations', 'picture-url',
2333
'site-standard-profile-request', 'summary', 'positions',

0 commit comments

Comments
 (0)