我目前正在使用Twitter API进行项目开发。
我的代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Newtonsoft.Json.Linq; // Added for JSON Library ( Doc)
using System.Xml;
using oAuthExample;
public partial class twitterInfo : System.Web.UI.Page
{
string url = "";
string xml = "";
public string name = "";
public string username = "";
public string profileImage = "";
public string followersCount = "";
public string noOfTweets = "";
public string recentTweet = "";
//Source http://www.aspdotnet-suresh.com/2012/05/add-twitter-login-authentication-to.html
protected void Page_Load(object sender, EventArgs e)
{
GetUserDetailsFromTwitter();
}
private void GetUserDetailsFromTwitter()
{
if (Request["oauth_token"] != null & Request["oauth_verifier"] != null)
{
imgTwitter.Visible = false;
tbleTwitInfo.Visible = true;
var oAuth = new oAuthTwitter();
//Get the access token and secret.
oAuth.AccessTokenGet(Request["oauth_token"], Request["oauth_verifier"]);
if (oAuth.TokenSecret.Length > 0)
{
url = "https://api.twitter.com/1.1/account/verify_credentials.json";
xml = oAuth.oAuthWebRequest(oAuthTwitter.Method.GET, url, String.Empty);
JObject o = JObject.Parse(xml);
name = Convert.ToString(o["name"]);
username = Convert.ToString(o["screen_name"]);
profileImage = Convert.ToString(o["profile_image_url"]);
followersCount = Convert.ToString(o["followers_count"]);
noOfTweets = Convert.ToString(o["statuses_count"]);
noOfTweets = Convert.ToString(o["birthday"]);
}
}
}
protected void imgTwitter_Click(object sender, ImageClickEventArgs e)
{
var oAuth = new oAuthTwitter();
if (Request["oauth_token"] == null)
{
//Redirect the user to Twitter for authorization.
//Using oauth_callback for local testing.
// R_ use the dynamic url director
// Call back URL to direct the user to the page
oAuth.CallBackUrl = "http://localhost:518/Account/TwitterInfo.aspx";
Response.Redirect(oAuth.AuthorizationLinkGet());
}
else
{
GetUserDetailsFromTwitter();
}
}
}
这段代码是 Twitter API 项目的一部分,用于返回用户的姓名、Twitter 用户名、个人资料图片、粉丝数和推文数量。
我知道 Twitter API 无法检索到用户的电子邮件地址。但我想要检索用户的个人资料 ID 和用户的个人资料链接…
可以有人告诉我需要从上面的代码中更改什么以检索这两个数据吗?
这里有一个链接提供完整的源代码。