【问题标题】:Python Twitter API using OAuth not providing email使用 OAuth 的 Python Twitter API 不提供电子邮件
【发布时间】:2018-12-31 11:47:19
【问题描述】:

我需要使用 Twitter API 来允许 Twitter 登录我的网站。使用 Python (Django),我已经能够获取用户的姓名和用户名以及其他相关数据,但不能获取用户的电子邮件。

我已经在apps.twitter.com上勾选了邮箱权限框,提示用户登录时将使用他/她的邮箱。但请求中不包含邮箱。

这是我的代码:

def get_user_details(self, response):

    """Return user details from Twitter account"""
    try:
        first_name, last_name = response['name'].split(' ', 1)
    except:
        first_name = response['name']
        last_name = ''
    print response
    return {'username': response['screen_name'],
            'email': response['email'],  
            'fullname': response['name'],
            'first_name': first_name,
            'last_name': last_name}

打印的响应包含 screen_namename,但不包含 email。我知道我的令牌是正确的,因为我得到了所有其他数据。

这是我正在进行的 API 调用:

TWITTER_CHECK_AUTH = 'https://%s/1.1/account/verify_credentials.json?include_email=true&include_entities=false&skip_status=true' % TWITTER_SERVER

有什么想法吗?

【问题讨论】:

    标签: python django twitter twitter-oauth


    【解决方案1】:

    您似乎在应用设置中遗漏了一些值。文档提到,为了检索用户的电子邮件地址,必须提供隐私政策 url 和服务条款 url。

    The "Request email addresses from users" checkbox is available under the app permissions on developer.twitter.com. Privacy Policy URL and Terms of Service URL fields must be completed in the app settings in order for email address access to function. If enabled, users will be informed via the oauth/authorize dialog that your app can access their email address.

    【讨论】:

    • 我们已经检查了邮箱并附上了我们的隐私政策/服务条款链接。我们的用户被提示该应用程序访问他们的电子邮件。但是这些电子邮件没有出现在请求中。您能想到我们可能缺少的其他设置吗?
    • 您确定用户有关联的电子邮件地址并且该电子邮件地址是经过验证的吗?
    • 您可以在删除现有令牌并重新验证用户身份后尝试吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-22
    • 2018-04-18
    • 1970-01-01
    • 2012-01-31
    • 2014-05-02
    • 1970-01-01
    • 2015-01-09
    相关资源
    最近更新 更多