I am trying to implement twitter login in ASP.Net with C#. I want to fetch the registered email address of the twitter user but my code is giving error:
An error occurred while parsing the Twitter response
This might be because dataTable.Rows[0]["email"].ToString() is invalid here. However, other details are being fetched perfectly. Following is my code:
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();
Code of OAuthWebRequest is as under:
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;
Please tell me how to fetch the email address from twitter with this code.
The email address is not available on the users/show endpoint. You need to use the validate_credentials endpoint.