如何使用Xamarin.Auth库获取Twitter用户电子邮件

时间:2017-02-13 12:27:55

标签: email twitter xamarin oauth twitter-oauth

我正在尝试为我的xamarin应用实施Twitter身份验证。我在开发者控制台上选中了“从用户处请求电子邮件地址”选项,但我无法在用户信息中收到电子邮件。我做错了吗

var Twitterauth = new OAuth1Authenticator(

consumerKey: "XXXX",
consumerSecret: "XXX",
requestTokenUrl:new Uri("https://api.twitter.com/oauth/request_token"),
authorizeUrl:    new Uri("https://api.twitter.com/oauth/authorize"),
accessTokenUrl:  new Uri("https://api.twitter.com/oauth/access_token"),
callbackUrl:     new Uri("http://www.isportfoy.com.tr/tr/anasayfa") 

);

Twitterauth.Completed += (s, ee) =>

{
   if (ee.IsAuthenticated)
        {

           var request = new OAuth1Request(
                        "GET",
                         new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"),
                        null,
                        ee.Account);

                    request.GetResponseAsync().ContinueWith(t =>
                    {
                        var res = t.Result;
                        var resString = res.GetResponseText();
                        Console.WriteLine("Result Text: " + resString);
                    });
}
                else 
                {

                }

            };

2 个答案:

答案 0 :(得分:2)

Twitter API要求我们在回复中指明我们是否要用户电子邮件。

根据Twitter文档,可以将include_email发送为真。

完整文档:https://dev.twitter.com/rest/reference/get/account/verify_credentials

答案 1 :(得分:0)

if (e.IsAuthenticated)
{
    Dictionary<string, string> param = new Dictionary<string, string>();
    param.Add("include_email","true");
    var request = new OAuth1Request(
        "GET",
        new Uri("https://api.twitter.com/1.1/account/verify_credentials.json"),
        param,
        e.Account);
}