![](/img/trans.png)
[英]403 Forbidden Access to posting shares denied for Linkedin API using python-linkedin library
[英]Getting OAuth access token for LinkedIn using python-linkedin library
我正在嘗試使用帶有以下代碼的python-linkedin庫獲取LinkedIn用戶訪問令牌。 它為我提供了訪問代碼,但是在獲取access_code之后卻沒有指向其他部分。
from linkedin import linkedin
from lnkd.settings import LINKEDIN_CONSUMER_KEY, LINKEDIN_CONSUMER_SECRET, RETURN_URL
from django.http import HttpResponseRedirect, HttpResponse
def get_linkedin_token(request):
authentication = linkedin.LinkedInAuthentication(
LINKEDIN_CONSUMER_KEY,
LINKEDIN_CONSUMER_SECRET,
RETURN_URL,
linkedin.PERMISSIONS.enums.values()
)
access_code = request.GET.get('code')
if code is None:
application = linkedin.LinkedInApplication(authentication)
return HttpResponseRedirect(authentication.authorization_url)
else:
authentication.authorization_code = access_code
access_token = authentication.get_access_token()
return Httpresponse(access_token)
我究竟做錯了什么?
我知道如何逐步進行連接,我始終使用OAuth步驟,並且對我有效,並經過XING和Linkedin測試:
from rauth import OAuth1Service
import webbrowser
CLIENT_ID = 'your client ID'
CLIENT_SECRET = 'your client secret'
RETURN_URL = "http://localhost:8000"
BASE_URL = 'https://api.linkedin.com'
AUTHORIZATION_URL = BASE_URL +'/uas/oauth/authenticate'
REQUEST_TOKEN_URL = BASE_URL +'/uas/oauth/requestToken'
ACCESS_TOKEN_URL = BASE_URL + '/uas/oauth/accessToken'
linkedin = OAuth1Service(
name='linkedin',
consumer_key=CLIENT_ID,
consumer_secret=CLIENT_SECRET,
request_token_url=REQUEST_TOKEN_URL,
access_token_url=ACCESS_TOKEN_URL,
authorize_url=AUTHORIZATION_URL,
base_url=BASE_URL)
token, token_secret = linkedin.get_request_token(
method='GET',
params={'oauth_callback': 'oob'})
url = linkedin.get_authorize_url(token)
webbrowser.open(url)
pin = raw_input('PIN:')
session = linkedin.get_auth_session(
token,
token_secret,
method='POST',
data={'oauth_verifier': pin})
現在,您有了一個名為“會話”的變量,該變量可以處理GET,POST和PUT請求。 例如,對於Xing,我沒有在Linkedin上嘗試過,但應該是這樣的:
#Find all IDs from your contacts list
search = "/v1/users/me/contact_ids"
res_ids = session.get(search,params={'format':'json'})
res_ids = res_ids.json()
print res_ids
# PUT a new webpage in your profil
res = session.put(
'/v1/users/me/web_profiles/homepage',
{'url[]': 'http://stackoverflow.com/questions/25183197'}
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.