繁体   English   中英

用Twitter登录不发送电子邮件

[英]Login with twitter is not sending Email

我正在尝试使用C#在ASP.Net中实现Twitter登录。 我想获取Twitter用户的注册电子邮件地址,但是我的代码给出了错误:

解析Twitter响应时发生错误

这可能是因为dataTable.Rows [0] [“ email”]。ToString()在此处无效。 但是,其他细节正在完美地获取。 以下是我的代码:

empty = "https://api.twitter.com/1.1/users/show.json";
str = twitterAuth.OAuthWebRequest(TwitterAuth.Method.GET, empty, string.Format("screen_name={0}", screenName));
dataTable = JsonStringToDataTable(str);
objTwitterBO.TwitterUserEmailId = dataTable.Rows[0]["email"].ToString();
objTwitterBO.TwitterUserID = dataTable.Rows[0]["Id"].ToString();
objTwitterBO.TwitterUserPhotoUrl = dataTable.Rows[0]["profile_image_url"].ToString();
objTwitterBO.TwitterUserName = dataTable.Rows[0]["name"].ToString();
objTwitterBO.TwitterUserScreenName = dataTable.Rows[0]["screen_name"].ToString();

OAuthWebRequest的代码如下:

string empty = string.Empty;
      string str = string.Empty;
        string empty1 = string.Empty;
        if ((method == TwitterAuth.Method.POST || method == TwitterAuth.Method.DELETE ? true : method == TwitterAuth.Method.GET))
        {
            if (postData.Length > 0)
            {
                NameValueCollection nameValueCollection = HttpUtility.ParseQueryString(postData);
                postData = string.Empty;
                string[] allKeys = nameValueCollection.AllKeys;
                for (int i = 0; i < (int)allKeys.Length; i++)
                {
                    string str1 = allKeys[i];
                    if (postData.Length > 0)
                    {
                        postData = string.Concat(postData, "&");
                    }
                    nameValueCollection[str1] = HttpUtility.UrlDecode(nameValueCollection[str1]);
                    nameValueCollection[str1] = TwitterBase.UrlEncode(nameValueCollection[str1]);
                    postData = string.Concat(postData, str1, "=", nameValueCollection[str1]);
                }
                if (url.IndexOf("?") <= 0)
                {
                    url = string.Concat(url, "?");
                }
                else
                {
                    url = string.Concat(url, "&");
                }
                url = string.Concat(url, postData);
                string postDataplus = "&include_email=true";
                url = string.Concat(url, postDataplus);

            }
        }
        Uri uri = new Uri(url);
        string str2 = this.GenerateNonce();
        string str3 = this.GenerateTimeStamp();
        string str4 = base.GenerateSignature(uri, this.ConsumerKey, this.ConsumerSecret, this.Token, this.TokenSecret, this.CallBackUrl, this.OAuthVerifier, method.ToString(), str3, str2, out empty, out str);
        str = string.Concat(str, "&oauth_signature=", TwitterBase.UrlEncode(str4));
        if ((method == TwitterAuth.Method.POST ? true : method == TwitterAuth.Method.DELETE))
        {
            postData = str;
            str = string.Empty;
        }
        if (str.Length > 0)
        {
            empty = string.Concat(empty, "?");
        }
        empty1 = this.WebRequest(method, string.Concat(empty, str), postData);
        return empty1;

请告诉我如何使用此代码从Twitter获取电子邮件地址。

该电子邮件地址在用户/显示端点上不可用。 您需要使用validate_credentials端点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM