【问题标题】:How to get the email address of twitter user with twitter api如何使用 twitter api 获取 twitter 用户的电子邮件地址
【发布时间】:2012-05-10 18:43:55
【问题描述】:

我想在我的网站上添加一个“使用 twitter 登录”的插件,并且在用户允许我的 twitter 应用程序访问他们的数据后,我的网站需要获取用户的 twitterID 和电子邮件。我浏览了 twitter 开发文档,但似乎总是关于 OAuth 的复杂示例。是否有捷径可寻?我已经为facebook放了同类型的插件,非常简单。谢谢!

【问题讨论】:

  • 嗨@Harshit:你是如何通过 twitter API 获得email 的。我也陷入了同样的问题。我在这里问了stackoverflow.com/questions/36284336/… 的问题。如果您有解决方案,请帮助我Bhai

标签: c# asp.net api twitter


【解决方案1】:

如果 twitter 不提供任何 API,那么foursquare如何检索它们?

  • Foursquare 可以列出用户在 Twitter 上注册的foursquare-friends。
  • 它还提供API,显示用户的“foursquare 好友列表”中经常出现的好友以及用户的“twitter 关注者列表”。

在上述两种情况下,只能通过电子邮件进行比较。

【讨论】:

    【解决方案2】:

    您可以通过 NO 方式获取 twitter 用户的电子邮件地址。 Twitter 不提供:https://dev.twitter.com/docs/faq#6718

    【讨论】:

    • Twitter 现在确实提供了电子邮件地址。请参阅@HenryP 回复。
    【解决方案3】:

    来自 twitter api 常见问题解答 https://dev.twitter.com/docs/faq

    如何获取用户的电子邮件地址?

    如果您想要用户的电子邮件地址,则需要向用户索取 在您自己的应用程序和服务范围内。推特 API 不提供用户的电子邮件地址作为 OAuth 的一部分 代币协商过程,也不提供其他获取方式。

    【讨论】:

      【解决方案4】:

      https://dev.twitter.com/rest/reference/get/account/verify_credentials 请求用户的电子邮件地址

      请求用户的电子邮件地址要求您的应用程序被 Twitter 列入白名单。要请求访问权限,请please use this form

      一旦列入白名单,“向用户请求电子邮件地址”复选框将在您在 apps.twitter.com 上的应用权限下可用。隐私政策 URL 和服务条款 URL 字段也将在电子邮件访问所需的设置下可用。如果启用,将通过 oauth/authorize 对话框通知用户您的应用可以访问他们的电子邮件地址。

      【讨论】:

        【解决方案5】:

        转到https://support.twitter.com/forms/platform 选择“我需要访问特殊权限” 输入应用程序名称和 ID。这些可以通过https://apps.twitter.com/获得——应用ID是你点击应用后浏览器地址栏中的数字部分。 权限请求:“电子邮件地址” 提交并等待回复 在您的请求获得批准后,您的 Twitter 应用程序的“权限”部分中会添加一个附加权限设置。转到“其他权限”,然后勾选“向用户请求电子邮件地址”复选框。

        【讨论】:

          【解决方案6】:

          Twitter 不提供电子邮件地址,这就是许多使用 OAuth 的网站不实施 Twitter 的原因;因为用户的电子邮件地址是注册过程的一部分。

          【讨论】:

            【解决方案7】:

            无法通过 twitter 获取电子邮件,twitter 不会在 api 响应中提供电子邮件。

            see official twitter api link:

            【讨论】:

              【解决方案8】:

              我正在研究 C#.Net,我使用了 Tweetinvi API,它易于使用并且有很好的文档。

              为了回答你的问题,有可能得到用户的电子邮件和所有数据。

              1st:您需要在“apps.twitter.com”上创建您的 Twitter 应用程序并进行注册。然后在应用程序管理中,您会找到一个“权限”选项卡,在页面末尾有一个复选框,说明您是否需要电子邮件信息。您必须提供指向您的隐私条款的链接,以便用户阅读并同意与您的应用共享信息,您可以使用“https://google.com”,但建议提供有效链接。

              仅此而已。在代码中,您只需要对用户进行身份验证并获取您需要的数据即可。

              using System;
              using System.Collections.Generic;
              using System.Diagnostics;
              using System.Linq;
              using System.Text;
              using System.Threading.Tasks;
              using Tweetinvi;
              using Tweetinvi.Models;
              
              namespace APIS
              {
                  public class TwitterConfig
                  {
                      IAuthenticationContext authenticationContext;
              
                      /// <summary>
                      /// Le indica a twitter que va a hacer una consulta de crendenciales. Esta consulta va a generar un PIN en caso de que sea correcto
                      /// y el usuario tiene que digitar el pin.
                      /// </summary>
                      public void RequestForCredentials()
                      {
                          var appCredentials = new TwitterCredentials("CONSUMER-KEY", "CONSUMER-SECRET"); //GET THE CONSUMER INFORMATION ON THE TWITTER APP MANAGEMENT
              
                          authenticationContext = AuthFlow.InitAuthentication(appCredentials);
              
              
                          //This opens a web-browser and asks to the twitter client 
                          //to accept the terms, and twitter gives a code and the user
                          // have to introduce it on the app (use the AuthByPin(String pin) method )
                          //Thats the PIN for auth the user and then get the data
                          Process.Start(authenticationContext.AuthorizationURL);
                      }
              
                      /// <summary>
                      /// Metodo que solicita un PIN que un usuario de Twitter al aceptar las condiciones se le brindó y este lo introdujo en la app
                      /// para ser autenticado.
                      /// </summary>
                      /// <param name="pin">PIN del usuario</param>
                      /// <returns>IAuthenticatedUser devuelve el usuario autenticado y con todos los datos.</returns>
                      public IAuthenticatedUser AuthByPin(String pin) 
                      {
                          try
                          {
                              // Con este código PIN ahora es posible recuperar las credenciales de Twitter 
                              var userCredentials = AuthFlow.CreateCredentialsFromVerifierCode(pin, authenticationContext);
              
                              // Use las credenciales del usuario en su aplicación 
                              Auth.SetCredentials(userCredentials);
              
                              var user = User.GetAuthenticatedUser();
                              return user; 
                          }
                          catch (Exception e)
                          {
                              Console.WriteLine(e);
                              throw new ApplicationException("Problema al autenticar.", e);
                          }
                      }
                  }
              }
              </code>
              

              有什么问题可以问我

              【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2013-11-06
              • 1970-01-01
              • 1970-01-01
              • 2011-05-06
              • 2016-10-12
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多