Django-LinkedIn API-客户端错误(410)-/ complete / linkedin-oauth2 /处的HTTPError

时间:2019-05-07 10:12:11

标签: django access-token linkedin-api http-error

我需要从用户的LinkedIn个人资料中获取一些信息,以填写我的申请表的现有字段。所以我正在使用LinkedIn API(我已经在linkedin中创建了应用程序,并具有client_Key,client_Secret,r_liteprofile和r_emailaddress权限)。现在它提示我使用linkedIn登录并请求“允许”权限(在此提示之前都可以),但是在下一页中,我遇到了以下错误,而不是显示带有用户信息的json文件。

“”“ 在/ complete / linkedin-oauth2 /

处出现HTTPError

410客户端错误:网址为https://api.linkedin.com/v1/people/~:(first-name,id,last-name)?oauth2_access_token=AQVpVZCnhj2oLkzUvQytDU89kJUMm5yEIadV0BZMid3WVqPSVdOiJIePGIH7ZL7i3M5gppOlbUqpS68rDaaio56Y-nkC3Njpvf91v8WUPxQ8t-3uqJRzCC_MdrKUpntLalp24Eo2BMjpYIKeHGdxjFIlaMt9tszkIVHpPcZA2-dgbqOBrvt9-QE4P91bTXqBBkrtHEXg9F560OvltnQDgc0U1xwO-5yOT5LjlqAtvDJ_gMf3G8rZ9cdkayq4aP1CO-ljglGqlJb4uxorPRg7qPqqkNaAmQjXploM0KVQ6pK7nidP4zC2l7WW1aqg38GRDe8AM8jzaiIkg-SX3JfCJA28fT9H8A&format=json

“”“

下面是我的代码,我有什么想念的吗?...我是Django的新手,请帮助我修复它?

我尝试获取确切的访问令牌格式,例如{访问令牌:XXXXX,到期时间:XXX},网址为https://www.linkedin.com/oauth/v2/accessToken?grant_type=client_credentials&client_id=[my_client_ID]&client_secret=[my_client_secret],但我没有得到答复。

{“错误”:“ access_denied”,“错误描述”:“不允许该应用程序创建应用程序令牌”}

我该如何实现?

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'crispy_forms',
    'bootstrap4',
    'social_django',

]

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
    'social_django.middleware.SocialAuthExceptionMiddleware',
]

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [os.path.join(BASE_DIR, 'templates')],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'social_django.context_processors.backends',
                'social_django.context_processors.login_redirect',
            ],
        },
    },
]

AUTHENTICATION_BACKENDS = (
    'social.backends.linkedin.LinkedinOAuth2',
    'django.contrib.auth.backends.ModelBackend',
)

SOCIAL_AUTH_LINKEDIN_OAUTH2_KEY = 'my_client_ID'
SOCIAL_AUTH_LINKEDIN_OAUTH2_SECRET = 'my_client_secret'

SOCIAL_AUTH_LINKEDIN_OAUTH2_SCOPE =  ['r_liteprofile']
SOCIAL_AUTH_LINKEDIN_OAUTH2_FIELD_SELECTORS = ['r_emailaddress']
SOCIAL_AUTH_LINKEDIN_OAUTH2_EXTRA_DATA = [('id', 'id'),
                               ('firstName', 'first_name'),
                               ('lastName', 'last_name'),
                                ('emailAddress', 'email_address')]

SOCIAL_AUTH_LOGIN_REDIRECT_URL = '/home/'
SOCIAL_AUTH_LOGIN_URL = '/'

```[the error I'm getting][1]


  [1]: https://i.stack.imgur.com/ECS3N.png

0 个答案:

没有答案