C# 使用twitter登录不会发送电子邮件

C# 使用twitter登录不会发送电子邮件,c#,asp.net,twitter,twitter-oauth,twitter-login,C#,Asp.net,Twitter,Twitter Oauth,Twitter Login,我正在尝试用C#在ASP.Net中实现twitter登录。我想获取twitter用户的注册电子邮件地址,但我的代码给出错误: 分析Twitter响应时出错 这可能是因为dataTable.Rows[0][“email”].ToString()在此处无效。然而,其他细节正在被完美地捕捉。以下是我的代码: empty = "https://api.twitter.com/1.1/users/show.json"; str = twitterAuth.OAuthWebRequest(TwitterAu

我正在尝试用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;
string empty=string.empty;
string str=string.Empty;
stringempty1=string.Empty;
if((method==TwitterAuth.method.POST | | method==TwitterAuth.method.DELETE?true:method==TwitterAuth.method.GET))
{
如果(postData.Length>0)
{
NameValueCollection NameValueCollection=HttpUtility.ParseQueryString(postData);
postData=string.Empty;
字符串[]allKeys=nameValueCollection.allKeys;
对于(int i=0;i<(int)allKeys.Length;i++)
{
字符串str1=所有键[i];
如果(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)
{
empty=string.Concat(空,“?”);
}
empty1=this.WebRequest(方法,string.Concat(empty,str),postData);
返回空1;

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

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

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

我的代码出现错误。
什么错误?无法解析因为它没有找到“电子邮件”在响应中,这意味着您需要找出Twitter不返回电子邮件id的原因。您需要检查您传递的屏幕名是否允许将电子邮件id共享给Twitter API客户端。在我的Twitter应用程序中,允许获取电子邮件id,但我无法使用代码在此处获取。您是否随请求一起发送适当的令牌uest?该令牌是否具有适当的授权类型?
我的代码出现错误
什么错误?它无法解析,因为它没有找到“电子邮件”在响应中,这意味着您需要找出Twitter不返回电子邮件id的原因。您需要检查您传递的屏幕名是否允许将电子邮件id共享给Twitter API客户端。在我的Twitter应用程序中,允许获取电子邮件id,但我无法使用代码在此处获取。您是否随请求一起发送适当的令牌uest?该代币是否具有适当的授权类型?感谢您的回复@Andy Piper…您能在我的代码中添加代码来解决我的问题吗?不幸的是,我对ASP.NET不太熟悉,无法在这里提供帮助。感谢您的回复@Andy Piper…您能在我的代码中添加代码来解决我的问题吗?不幸的是,我不是我对ASP.NET不够熟悉,无法在此提供帮助。