将 Twitter OAuth Echo 用于 verify_credential,如何接收电子邮件?
Using Twitter OAuth Echo for verify_credential, how can I get email?
我有移动应用程序,我需要在 Twitter 上注册用户。
我正在为 OAuth Echo 获取参数 X-Auth-Service-Provider 和 X-Verify-Credentials-Authorization 并将它们发送到服务器
服务器调用 verify_credentials 并获取 Twitter 用户配置文件。
但是这个配置文件不包含用户的电子邮件,我如何在后端获取用户的电子邮件,同时在移动应用程序中授权用户?
要请求用户的电子邮件地址,您的应用程序需要被 Twitter 列入白名单。为此,您需要:
- 在 Twitter API 政策支持上填写以下 form。
- Select
I need access to special permissions
选项。
- 您需要填写您的应用程序名称和 ID(您可以从 https://apps.twitter.com 获取这些信息)。
- 在权限列表中,select您需要的权限。在你的情况下,它应该是
Email address
.
- 提交
一旦您的请求获得批准或者您已经被列入白名单,您可以返回 https://apps.twitter.com,在应用权限部分下,一个新的复选框 Request email addresses from users
将可用。您需要启用这个新选项。隐私政策 URL 和服务条款 URL 字段也将可用。
此时,您可以将 include_email
参数添加到您的 account/verify_credentials
请求中。
一些相关要点:
- 用户将被告知您的应用程序在登录过程中请求电子邮件地址。
- 你只会得到经过验证的电子邮件地址,如果用户没有提供任何电子邮件地址或没有验证它,你会得到
null
。
- 如果您已有经过身份验证的用户,则需要重新生成用户访问令牌才能获取电子邮件地址。
如果您的应用已按照建议列入白名单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 header
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"
}
如果您有任何疑虑,请告诉我。
我有移动应用程序,我需要在 Twitter 上注册用户。
我正在为 OAuth Echo 获取参数 X-Auth-Service-Provider 和 X-Verify-Credentials-Authorization 并将它们发送到服务器
服务器调用 verify_credentials 并获取 Twitter 用户配置文件。
但是这个配置文件不包含用户的电子邮件,我如何在后端获取用户的电子邮件,同时在移动应用程序中授权用户?
要请求用户的电子邮件地址,您的应用程序需要被 Twitter 列入白名单。为此,您需要:
- 在 Twitter API 政策支持上填写以下 form。
- Select
I need access to special permissions
选项。 - 您需要填写您的应用程序名称和 ID(您可以从 https://apps.twitter.com 获取这些信息)。
- 在权限列表中,select您需要的权限。在你的情况下,它应该是
Email address
. - 提交
一旦您的请求获得批准或者您已经被列入白名单,您可以返回 https://apps.twitter.com,在应用权限部分下,一个新的复选框 Request email addresses from users
将可用。您需要启用这个新选项。隐私政策 URL 和服务条款 URL 字段也将可用。
此时,您可以将 include_email
参数添加到您的 account/verify_credentials
请求中。
一些相关要点:
- 用户将被告知您的应用程序在登录过程中请求电子邮件地址。
- 你只会得到经过验证的电子邮件地址,如果用户没有提供任何电子邮件地址或没有验证它,你会得到
null
。 - 如果您已有经过身份验证的用户,则需要重新生成用户访问令牌才能获取电子邮件地址。
如果您的应用已按照建议列入白名单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 header
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"
}
如果您有任何疑虑,请告诉我。