php 我们可以从 Twitter oauth API 获取电子邮件 ID 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22627083/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:09:07  来源:igfitidea点击:

Can we get email ID from Twitter oauth API?

phptwittertwitter-oauth

提问by Vinoth Babu

How to get email id of the user who accepted my Twitter application?

如何获取接受我的 Twitter 应用程序的用户的电子邮件 ID?

I have gone through lot of forums. But they have mentioned, it is not possible. Also those posts are older than a year. May I know whether it is possible to get the user email id through twitter API using PHP?

我浏览了很多论坛。但他们已经提到,这是不可能的。这些帖子也超过一年。我可以知道是否可以使用 PHP 通过 Twitter API 获取用户电子邮件 ID?

I am getting Twitter user details using the following URL:

我使用以下 URL 获取 Twitter 用户详细信息:

https://api.twitter.com/1.1/account/verify_credentials.json

https://api.twitter.com/1.1/account/verify_credentials.json

回答by aleemb

This is now possible by filling out a form to request elevated permissions:

现在可以通过填写表格来请求提升权限

  1. Go to https://support.twitter.com/forms/platform
  2. Select "I need access to special permissions"
  3. Enter Application Name and ID. These can be obtained via https://apps.twitter.com/-- the application ID is the numeric part in the browser's address bar after you click your app.
  4. Permissions Request: "Email address"
  5. Submit & wait for response
  6. After your request is granted, an addition permission setting is added in your twitter app's "Permission" section. Go to "Additional Permissions" and just tick the checkbox for "Request email addresses from users".
  1. 转到https://support.twitter.com/forms/platform
  2. 选择“我需要访问特殊权限”
  3. 输入应用程序名称和 ID。这些可以通过https://apps.twitter.com/获得——应用程序 ID 是您点击应用程序后浏览器地址栏中的数字部分。
  4. 权限请求:“电子邮件地址”
  5. 提交并等待回复
  6. 在您的请求获得批准后,您的 twitter 应用程序的“权限”部分中会添加一个附加权限设置。转到“其他权限”,然后勾选“从用户请求电子邮件地址”复选框。

Note that user e-mail address has to be verified, otherwise Twitter refuses to provide it. (See include_emailparameter description in elevated permissionsdoc page.)

请注意,必须验证用户电子邮件地址,否则 Twitter 拒绝提供。(请参阅提升权限文档页面中的include_email参数说明。)

回答by Pran

Now you can fetch user email address from twitter API and it's a lot much easier. Just follow these steps...

现在您可以从 twitter API 获取用户电子邮件地址,这变得容易多了。只需按照以下步骤...

  1. Goto Twitter Apps

  2. Click on 'Create New App'

  3. Fill all required credentials and click on 'Create your Twitter application'

  4. Now click on 'Permissions' tab -> check 'Request email addresses from users' field and click on 'Update Settings'. (check given picture)

  5. Now in your PHP code, set all app details and add this code!

    $params = array('include_email' => 'true', 'include_entities' => 'false', 'skip_status' => 'true');

    $data = $connection->get('account/verify_credentials', $params); // get the data

    // getting twitter user profile details $twt_id = $data->id; //twitter user id $twt_email = $data->email; //twitter user email

  1. 转到Twitter 应用程序

  2. 点击“创建新应用”

  3. 填写所有必需的凭据,然后单击“创建您的 Twitter 应用程序”

  4. 现在单击“权限”选项卡 -> 选中“从用户请求电子邮件地址”字段并单击“更新设置”。(检查给定的图片)

  5. 现在在您的 PHP 代码中,设置所有应用程序详细信息并添加此代码!

    $params = array('include_email' => 'true', 'include_entities' => 'false', 'skip_status' => 'true');

    $data = $connection->get('account/verify_credentials', $params); // get the data

    // getting twitter user profile details $twt_id = $data->id; //twitter user id $twt_email = $data->email; //twitter user email

All Done. Hope it help you, good luck. ;)

全部完成。希望能帮到你,祝你好运。;)

enter image description here

在此处输入图片说明

回答by Kevin Traas

It is now possible to retrieve a user's email address from Twitter (if the user permits it, of course).

现在可以从 Twitter 检索用户的电子邮件地址(当然,如果用户允许的话)。

You'll need to apply to have your application white-listed to receive xAuth.

您需要申请将您的应用程序列入白名单才能接收 xAuth。

Check here for more info: https://dev.twitter.com/rest/reference/get/account/verify_credentials

在此处查看更多信息:https: //dev.twitter.com/rest/reference/get/account/verify_credentials

回答by Chirag Prajapati

Yes you can get email address.This is now possible by filling out a some permission.

是的,您可以获得电子邮件地址。现在可以通过填写一些许可来实现。

1.Go to this Link: https://apps.twitter.com/

1.转到此链接:https://apps.twitter.com/

2.After go to permission tab inside your created Application

2.在您创建的应用程序中转到权限选项卡后

3.Select Addition permission checkbox in your APP.

3.在您的应用程序中选择添加权限复选框。

4.After successfully update setting you can get email address from Twitter.

4.成功更新设置后,您可以从 Twitter 获取电子邮件地址。

If in some case you can not getting email address then please check your Oauth Api request url.

如果在某些情况下您无法获得电子邮件地址,请检查您的 Oauth Api 请求网址。

Your request url should be this type :https://api.twitter.com/1.1/account/verify_credentials.json?include_email=true

您的请求 url 应该是这种类型:https: //api.twitter.com/1.1/account/verify_credentials.json?include_email=true

回答by Hüseyin BABAL

It is not possible to get user's email address from twitter. You can see it here. You can open a form page on your callback page and get user's email address on that page. You can refer herefor example usage

无法从 Twitter 获取用户的电子邮件地址。你可以在这里看到它。您可以在回调页面上打开表单页面并在该页面上获取用户的电子邮件地址。您可以参考此处的示例用法

回答by danielserafimovik

Here is how I have done this in ASP.Net using linqtoTwitter library http://www.bigbrainintelligence.com/Post/get-users-email-address-from-twitter-oauth-ap

这是我如何使用 linqtoTwitter 库在 ASP.Net 中完成此操作 http://www.bigbrainintelligence.com/Post/get-users-email-address-from-twitter-oauth-ap

// call verify credentials api
var twitterCtx = new TwitterContext(authTwitter);
var verifyResponse =
      await
          (from acct in twitterCtx.Account
           where (acct.Type == AccountType.VerifyCredentials) && (acct.IncludeEmail == true)
           select acct)
          .SingleOrDefaultAsync();

if (verifyResponse != null && verifyResponse.User != null)
{
    User twitterUser = verifyResponse.User;
    //assign email to existing authentication object
    loginInfo.Email = twitterUser.Email;

}