Django allauth LinkedIn API没有返回完整的个人资料数据

问题描述 投票:1回答:3

我有一个应用程序,我正在尝试Django Allauth,特别是LinkedIn api。

我在我的设置中定义范围如下:

SOCIALACCOUNT_PROVIDERS = \
{
    'linkedin':
    {
        'SCOPE': ['r_fullprofile', 'r_emailaddress']
    }
}

我正在使用以下命令将此信息输出到模板:

{% extends 'base.html' %}
{% load auth_extras %}
{% load account %}
{% load socialaccount %}

{% block content %}
{% if user.is_authenticated %}

{% for key, value in user.socialaccount_set.all.0.extra_data.items %}
<ul>
    <li>{{ key }}: {{ value }}</li>
</ul>
{% endfor %}
{% endif %}
{% endblock content %}

当我通过LinkedIn授权帐户时,我可以看到它要求批准基本个人资料,电子邮件地址和完整个人资料。但是user.socialaccount_set.all.0.extra_data对象只有基本的配置文件和电子邮件地址数据。完整的个人资料数据怎么了?

另外,user.socialaccount_set.all.0.extra_data真的是访问提供商公开的所有数据的最佳方式吗?

django authentication oauth linkedin django-allauth
3个回答
3
投票

我最近遇到了这个问题并遇到了这个问题:https://github.com/pennersr/django-allauth/issues/397

简答:看来我们在settings.py中定义了额外的PROFILE_FIELDS,这些字段被复制到extra_data。

所以为了完整性,这里是我的settings.py(包括facebook和linkedin)

SOCIALACCOUNT_PROVIDERS = \
    {'facebook': {'SCOPE': ['email', 'user_about_me', 'user_birthday',
                            'user_education_history','user_work_history',
                            'user_hometown',
                            'user_location',
                            'user_religion_politics','user_subscriptions',
                            'read_stream',
                            'read_insights',
                            'read_friendlists',
                            'user_likes',
                            'user_interests',
                            'user_groups'
                            ],
                  'AUTH_PARAMS': {},
                  'METHOD': 'oauth2'
                },

     'linkedin': {'SCOPE': ['r_emailaddress', 'r_fullprofile', 'r_emailaddress', 'r_contactinfo', 'r_network'],
                  'PROFILE_FIELDS': ['id', 'first-name',
                              'last-name',
                              'email-address',
                              'picture-url',
                              'public-profile-url', 'skills', 'headline'
                  ]
     }
    }

我可以使用以下方式打印技能和标题:

@receiver(user_logged_in)
def populate_profile_login2(request, **kwargs):
{
    try:
        extra_data = kwargs.get('user').socialaccount_set.filter(provider='linkedin')[0].extra_data
        for key, value in extra_data.iteritems():
            print key, value
    except:
        print ' NOT LINKEDIN'


 }

1
投票

我正在使用新的linkedin_oauth2并遇到了同样的问题。我花了一点时间弄清楚我的错误,我使用了错误的提供商名称('linkedin'而不是'linkedin_oauth2')

希望这将有助于将来的其他人。

此(settings.py)配置按预期工作。

SOCIALACCOUNT_PROVIDERS = \
        'linkedin_oauth2': {'SCOPE': ['r_fullprofile', 'r_emailaddress'],
                  'PROFILE_FIELDS': ['id', 'first-name',
                              'last-name',
                              'email-address',
                              'picture-url',
                              'public-profile-url',
                              'skills', 'headline']}
        }

0
投票

在我的linkedin配置(settings.py)中,它适用于:

SOCIALACCOUNT_PROVIDERS = \
{
'linkedin': 
    {'SCOPE': [ 'r_emailaddress',
                'r_fullprofile',
                'r_emailaddress',
                'r_contactinfo',
                'r_network'],
      'PROFILE_FIELDS':
            [
                'id',
                'first-name',
                'last-name',

                'email-address',
                'picture-url',
                'public-profile-url',
                'skills',

                'headline',
                'industry',

                'num-connections',
                'positions',
                'interests',
                'languages',
                'certifications',
                'educations',
                'courses',
                'three-current-positions',
                'three-past-positions',
                'recommendations-received',
                'honors-awards'
            ]
    }
}

所有字段都定义在:http://developer.linkedin.com/documents/profile-fields

您必须确保您在“r_fullprofile”范围内以获取上述所有数据。

我正在使用:django-allauth == 0.14.2和Django == 1.5.1

我希望有所帮助!

© www.soinside.com 2019 - 2024. All rights reserved.