我有移动应用,我需要通过Twitter注册用户。
我正在为OAuth Echo获取参数X-Auth-Service-Provider和X-Verify-Credentials-Authorization并将它们发送到服务器
服务器调用verify_credentials并获取Twitter用户个人资料。
但是此个人资料不包含用户的电子邮件,如何在移动应用中授权用户的同时在后端获取用户的电子邮件?
答案 0 :(得分:3)
要请求用户的电子邮件地址,您的应用程序需要由Twitter列入白名单。要做到这一点,你需要:
public static function rememberUntil($seconds = 0)
{
if (self::$_unitTestEnabled) {
self::regenerateId();
return;
}
$cookieParams = session_get_cookie_params();
session_set_cookie_params(
$seconds,
//$cookieParams['path'],
//$cookieParams['domain'],
//$cookieParams['secure']
);
// normally "rememberMe()" represents a security context change, so should use new session id
self::regenerateId();
}
选项。I need access to special permissions
。一旦您的请求获得批准或者您已经列入白名单,您就可以返回https://apps.twitter.com并在应用权限部分下方,新的复选框Email address
将可用。您需要启用此新选项。隐私政策URL和服务条款URL字段也将可用。
此时,您可以将Request email addresses from users
参数添加到include_email
请求中。
一些相关要点:
account/verify_credentials
。答案 1 :(得分:2)
如果您的应用按照建议https://dev.twitter.com/rest/reference/get/account/verify_credentials
列入白名单或@Hideo建议
在服务器端你可以我们
获取请求: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"
}
如果您有任何疑虑,请告诉我。