【问题标题】:Using Twitter OAuth Echo for verify_credential, how can I get email?将 Twitter OAuth Echo 用于 verify_credential,如何获取电子邮件?
【发布时间】:2016-12-09 00:59:15
【问题描述】:

我有移动应用,我需要在 twitter 上注册用户。

我正在获取OAuth Echo 的参数 X-Auth-Service-Provider 和 X-Verify-Credentials-Authorization 并将它们发送到服务器

服务器调用verify_credentials 并获取 Twitter 用户配置文件。

但是此配置文件不包含用户的电子邮件,我如何在后端获取用户的电子邮件,同时在移动应用中授权用户?

【问题讨论】:

    标签: php android twitter twitter-oauth


    【解决方案1】:

    要请求用户的电子邮件地址,您的应用程序需要被 Twitter 列入白名单。为此,您需要:

    1. 在 Twitter API 政策支持上填写以下 form
    2. 选择I need access to special permissions 选项。
    3. 您需要填写您的应用程序名称和 ID(您可以从 https://apps.twitter.com 获取这些信息)。
    4. 在权限列表中,选择您需要的权限。在你的情况下,它应该是Email address
    5. 提交

    一旦您的请求获得批准或者您已经被列入白名单,您可以返回https://apps.twitter.com,并在应用权限部分下,一个新的复选框Request email addresses from users 将可用。您需要启用此新选项。隐私政策 URL 和服务条款 URL 字段也将可用。

    此时,您可以将include_email 参数添加到您的account/verify_credentials 请求中。

    一些相关点:

    • 将通知用户您的应用在登录过程中请求电子邮件地址。
    • 您只会获得经过验证的电子邮件地址,如果用户未提供任何电子邮件地址或未进行验证,您将获得null
    • 如果您已经拥有经过身份验证的用户,则需要重新生成用户访问令牌以获取电子邮件地址。

    【讨论】:

    • 重新生成用户令牌有帮助,非常感谢!
    【解决方案2】:

    如果您的应用按照建议被列入白名单https://dev.twitter.com/rest/reference/get/account/verify_credentials

    或者按照@Hideo的建议

    在服务器端你可以我们

    GET 请求:https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true

    使用以下类型 auth 1.0 http 标头

    Authorization: OAuth oauth_consumer_key="KgpUD2nx5UCH9DllSIM4D****",
                    oauth_nonce="77252745154355061291979480247359",
                    oauth_signature="jPd5e5Z5ibKDb40JUjAuDVpi9TU%3D",
                    oauth_signature_method="HMAC-SHA1",       oauth_timestamp="1471161684",
                    oauth_token="76472850016308****-qOqGdpxuVvT7Z7s5n9NFXqzIr11****",
                    oauth_version="1.0"
    

    这里 oauth_token 将获得这里建议的访问令牌http://oauth.net/core/1.0/#anchor12

    您将得到以下类型的响应:

    {
      "id": 75534037587985****,
      "id_str": "75534037587985****",
      "name": "tester",
      "screen_name": "*********",
      "location": "",
      "description": "",
      "url": null,
      "entities": {
        "description": {
          "urls": []
        }
      },
      "protected": false,
      "followers_count": 0,
      "friends_count": 19,
      "listed_count": 0,
      "created_at": "Tue Jul 19 09:55:54 +0000 2016",
      "favourites_count": 0,
      "utc_offset": null,
      "time_zone": null,
      "geo_enabled": false,
      "verified": false,
      "statuses_count": 0,
      "lang": "en",
      "contributors_enabled": false,
      "is_translator": false,
      "is_translation_enabled": false,
      "profile_background_color": "F5F8FA",
      "profile_background_image_url": null,
      "profile_background_image_url_https": null,
      "profile_background_tile": false,
      "profile_image_url": "http://abs.twimg.com/sticky/default_profile_images/default_profile_4_normal.png",
      "profile_image_url_https": "https://abs.twimg.com/sticky/default_profile_images/default_profile_4_normal.png",
      "profile_link_color": "2B7BB9",
      "profile_sidebar_border_color": "C0DEED",
      "profile_sidebar_fill_color": "DDEEF6",
      "profile_text_color": "333333",
      "profile_use_background_image": true,
      "has_extended_profile": false,
      "default_profile": true,
      "default_profile_image": true,
      "following": false,
      "follow_request_sent": false,
      "notifications": false,
      "email": "testerdaff@gmail.com"
    }
    

    如果您有任何疑虑,请告诉我。

    【讨论】:

      猜你喜欢
      • 2018-04-18
      • 2016-01-22
      • 2012-01-31
      • 2011-05-06
      • 1970-01-01
      • 2019-12-22
      • 1970-01-01
      • 2014-05-02
      • 2016-10-12
      相关资源
      最近更新 更多