C# 如何使用asp.net在twitter API上获取用户信息
我目前正在从事一个使用twitter API的项目 我有这样一个代码:C# 如何使用asp.net在twitter API上获取用户信息,c#,asp.net,twitter,C#,Asp.net,Twitter,我目前正在从事一个使用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
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();
}
}
}
此代码是要返回的TwitterAPI项目的一部分(名称、twitterusername、profileimage、关注者和tweets数量)。
我知道Twitter API不会检索用户的电子邮件地址。
但我想检索用户的配置文件ID和用户的配置文件链接。。。
有谁能告诉我,为了检索这两个数据,我应该对上面的代码做哪些更改
以下是完整的源代码。您用于帐户/验证\u凭据的代码看起来正常,如果正常,您可以使用相同的代码,但更改URL。account/verify_凭据将适用于经过身份验证的用户,但您必须使用它来指定任何用户。这里有一个端点,但同样地,它只适用于经过身份验证的用户 只有个人用户才能查看自己的设置页面。您可以将用户发送到,这是他们自己的个人资料页面,但他们需要登录才能看到。我不知道这是否符合您的要求,但您可以做的一件事是识别个人的公共twitter页面,如下所示:
string publicTwitterPage = "https://twitter.com/" + username;
在field guide上,它们对响应中的每个字段都有定义。对于用户对象,它是“id”。