Twitterizer 2.2 发送帮助

发布于 2024-09-10 20:16:29 字数 2167 浏览 4 评论 0原文

您好,我正在从我的 asp.net 网站发送 twitter 更新。我已经获得了授权,但是当它发送推文时我陷入了困境,这是我的代码:

  protected void btnAuth_Click(object sender, EventArgs e)
{
    // add these to web.config or your preferred location
    var consumerKey = ConfigurationManager.AppSettings["consumerKey"];
    var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

    //If User is not valid user
    if (Request.QueryString["oauth_token"] == null)
    {
        //Step 1: Get Request Token
        OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey,consumerSecret);

        //Step 2: Redirect User to Requested Token
        Response.Redirect("http://twitter.com/oauth/authorize?oauth_token="+ RequestToken.Token);
    }
    else
    {
        //For Valid User
        string Oauth_Token = Request.QueryString["oauth_token"].ToString();

        var accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, Oauth_Token, txtPIN.Text.Trim());

        lblMessage.Text = "<b>Hello "  + accessToken.ScreenName + ", Welcome to my Twitter App<b>";
        lblMessage.Text += "<br/> Token: " + accessToken.Token;
        lblMessage.Text += "<br/> TokenSecret: " + accessToken.TokenSecret;
        lblMessage.Text += "<br/> UserId: " + accessToken.UserId;
        lblMessage.Text += "<br/> VerificationString: " + accessToken.VerificationString;
    } 
}

 protected void  btnTweet_Click(object sender, EventArgs e)
{
    // add these to web.config or your preferred location
    var consumerKey = ConfigurationManager.AppSettings["consumerKey"];
    var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

    OAuthTokens accessToken = new OAuthTokens();
    accessToken.AccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    accessToken.AccessTokenSecret = "xxxxxxxxxxxxxxxxxxxx";
    accessToken.ConsumerKey = consumerKey;
    accessToken.ConsumerSecret = consumerSecret;

    TwitterStatus TweetStatus = new TwitterStatus();
    TweetStatus.Update(accessTokens, txtTweet.Text);                        
}   

我不知道如何获取 AccessToken 和 AccessToken。 AccessTokenSecret。任何帮助将非常感谢。

Hi I am working on sending twitter updates from my asp.net website. I have the authorization down but I am stuck when it gets to sending the tweet here is my code behind:

  protected void btnAuth_Click(object sender, EventArgs e)
{
    // add these to web.config or your preferred location
    var consumerKey = ConfigurationManager.AppSettings["consumerKey"];
    var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

    //If User is not valid user
    if (Request.QueryString["oauth_token"] == null)
    {
        //Step 1: Get Request Token
        OAuthTokenResponse RequestToken = OAuthUtility.GetRequestToken(consumerKey,consumerSecret);

        //Step 2: Redirect User to Requested Token
        Response.Redirect("http://twitter.com/oauth/authorize?oauth_token="+ RequestToken.Token);
    }
    else
    {
        //For Valid User
        string Oauth_Token = Request.QueryString["oauth_token"].ToString();

        var accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, Oauth_Token, txtPIN.Text.Trim());

        lblMessage.Text = "<b>Hello "  + accessToken.ScreenName + ", Welcome to my Twitter App<b>";
        lblMessage.Text += "<br/> Token: " + accessToken.Token;
        lblMessage.Text += "<br/> TokenSecret: " + accessToken.TokenSecret;
        lblMessage.Text += "<br/> UserId: " + accessToken.UserId;
        lblMessage.Text += "<br/> VerificationString: " + accessToken.VerificationString;
    } 
}

 protected void  btnTweet_Click(object sender, EventArgs e)
{
    // add these to web.config or your preferred location
    var consumerKey = ConfigurationManager.AppSettings["consumerKey"];
    var consumerSecret = ConfigurationManager.AppSettings["consumerSecret"];

    OAuthTokens accessToken = new OAuthTokens();
    accessToken.AccessToken = "xxxxxxxxxxxxxxxxxxxxxxxxxxxx";
    accessToken.AccessTokenSecret = "xxxxxxxxxxxxxxxxxxxx";
    accessToken.ConsumerKey = consumerKey;
    accessToken.ConsumerSecret = consumerSecret;

    TwitterStatus TweetStatus = new TwitterStatus();
    TweetStatus.Update(accessTokens, txtTweet.Text);                        
}   

I dont know how to get the AccessToken & AccessTokenSecret. Any help would be great thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

若相惜即相离 2024-09-17 20:16:29

当您调用 OAuthUtility.GetAccessToken 方法时,访问令牌和秘密值将从 Twitter 返回到您的应用程序:

var accessToken = OAuthUtility.GetAccessToken(consumerKey,consumerSecret,Oauth_Token,Request.QueryString["oauth_verifier"]);

一次性授权流程如下:
1)获取请求token
2) 将用户发送到 Twitter 登录并授予访问权限
3) 在回调 url 接收用户,从查询字符串中收集 oauth_token 和 oauth_verifier 值
4) 将请求令牌和验证者交换为访问令牌

获得访问令牌后,应将其存储起来,以便用户不需要再次执行该过程(访问令牌不会过期)。

我注意到您正在从用户那里收集 PIN 值,但您的应用程序似乎是一个网站。 Web 流程(不是基于 PIN 的身份验证)将提供更加愉快的用户体验。

如果您有更多问题,请将其发布到 Twitterizer 论坛,http://forums.twitterizer.net

The access token and secret values are returned to your application from Twitter when you call the OAuthUtility.GetAccessToken method:

var accessToken = OAuthUtility.GetAccessToken(consumerKey, consumerSecret, Oauth_Token, Request.QueryString["oauth_verifier"]);

The one-time authorization process goes as follows:
1) Get a request token
2) Send the user to Twitter to login and grant access
3) Receive the user at the callback url, collect the oauth_token and oauth_verifier values from the querystring
4) Exchange the request token and verifier for the access token

After you have the access token, you should store it so that the user isn't required to go through the process again (the access token does not expire).

I noticed that you're collecting a PIN value from the user, but it appears as though your application is a website. The web flow (not pin-based authentication) will provide a much more pleasant user experience.

If you have more questions, please post them to the Twitterizer forums, http://forums.twitterizer.net.

や三分注定 2024-09-17 20:16:29

成功登录后,您只需在 OAuthTokens 中设置所有四个变量(AccessToken 和 AccessTokenSecret 都会在成功的 OAuthUtility.GetAccessToken 上返回)。

我建议您在经过身份验证后将 AccessToken 和 AccessToken 存储在 Cookie 中。

创建一个静态类,您可以在其中返回所有四个令牌,并检查是否提供了所有四个值,否则会注销。

After a successful login, you just have to set all four variables in your OAuthTokens (AccessToken & AccessTokenSecret are both return on successful OAuthUtility.GetAccessToken)

I suggest you store you AccessToken and AccessToken in a Cookie once Authenticated.

Create a Static Class where you can return all four tokens and do a check if all four values are supplied ELSE logged-out.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文