如何从我的asp.net web appln连接到twitter [英] How to connect to twitter from my asp.net web appln

查看:86
本文介绍了如何从我的asp.net web appln连接到twitter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



PLs向我发送代码或坚持使用C#在哪里可以找到我的asp.net网站上的twitter集成。



如果我在开发人员进入网站时也会澄清我发出的错误是网站无效,甚至要求占位符请说明我的疑问。



预付谢谢,

Vinay

Hi,
PLs send me the code or insist the site where can I find the twitter integration to my asp.net website using C#.

Pls also clarify me when I am entering the website in developer it is throwing the error saying website is not valid and even asking place a placeholder pls clarify my doubts.

Advance Thanks,
Vinay

推荐答案

推特的.NET界面可在GoogleCode Twitterizer上找到http://code.google.com/p/twitterizer/ [ ^ ]



Twitterizer库包含许多类,用于对两者之间交换的信息进行建模客户端和服务器在进行Twitter API调用时,以及发出HTTP请求所需的低级管道,并将对象模型序列化为适当的XML和版本-versa。图书馆的主要工具是Twitter课程。使用此课程时,您需要提供要与其集成的Twitter帐户的用户名和密码。示例代码如下:



.NET interface for Twitter is available at GoogleCode Twitterizer http://code.google.com/p/twitterizer/[^]

The Twitterizer library contains a number of classes that model the information exchanged between the client and the server when making Twitter API calls, along with the low-level plumbing necessary to make the HTTP requests and to serialize the object model into the appropriate XML and vice-a-versa. The main workhorse of the library is the Twitter class. When using this class you'll want to provide the username and password of the Twitter account that you want to integrate with. Sample code is as below:

Twitter twit = new Twitter(username, password);
TwitterStatusCollection tweets = twit.Status.UserTimeline();
twit.Status.Update(tweet_text);





要返回一组最近的推文,请使用以下代码:





To return a set of recent tweets, use the below code:

TwitterParameters twitParameters = new TwitterParameters();
twitParameters.Add(TwitterParameterNames.Count, numberOfTweetsToGet);
twit.Status.UserTimeline(twitParameters);


登录页面使用Twitter登录点击。

Login Page Login With Twitter Click.
protected void btnLogTwitter_Click(object sender, EventArgs e)
{
    OAuthHelper oauthhelper = new OAuthHelper();
    oauthhelper.LoginWithTwitter();

    if (string.IsNullOrEmpty(oauthhelper.oauth_error))
    {
        Response.Redirect(string.Format("{0}?oauth_token={1}", OAuthHelper.GetAUTHORIZE, oauthhelper.oauth_request_token));
    }
    else
    {
        Response.Write(oauthhelper.oauth_error);
    }
}





Twitter重定向到此页面(Callback Url在您的应用程序中注册twitter。)



Twitter redirects to this page (Callback Url register with your application on twitter.)

public partial class oauthreturn : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["oauth_token"] != null && Request.QueryString["oauth_verifier"]!=null)
        {
            string oauth_token = Request.QueryString["oauth_token"];
            string oauth_verifier = Request.QueryString["oauth_verifier"];

            OAuthHelper oauthhelper = new OAuthHelper();
            oauthhelper.GetUserTwAccessToken(oauth_token, oauth_verifier);

            if (string.IsNullOrEmpty(oauthhelper.oauth_error))
            {
                Session["twtoken"] = oauthhelper.oauth_access_token;
                Session["twsecret"] = oauthhelper.oauth_access_token_secret;
                Session["twuserid"] = oauthhelper.user_id;
                Session["twname"] = oauthhelper.screen_name;


                Response.Write("AccessToken=" + oauthhelper.oauth_access_token);
                Response.Write("<br />Access Secret=" + oauthhelper.oauth_access_token_secret);
                Response.Write("<br />Screen Name=" + oauthhelper.screen_name);
                Response.Write("<br />Twitter User ID=" + oauthhelper.user_id);
            }
            else
                Response.Write(oauthhelper.oauth_error);
        }
    }

}





了解它是如何工作的以及它是什么流程oauth 1.0,下载oAuthHelper类和oAuthUtility。

使用asp.net中的oauth身份验证登录Twitter并获取访问令牌,屏幕名称和用户ID


这篇关于如何从我的asp.net web appln连接到twitter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆