Twitter 和 Winform C# 应用程序让我秃头
好吧,twitter 对于社交媒体来说可能很棒,但是对于我只是为了好玩而尝试创建的一个小应用程序来说,它变成了一场噩梦。我到处搜索都没有找到关于如何使用 api 的很好的解释。
我正在使用 TweetSharp api,我想做的就是让用户允许我的应用程序并能够从应用程序发布到他们的 Twitter。
当应用程序给出一个 pin 码供用户输入时,我的问题就出现了……用户会在哪里输入它?好吧,这就是我到目前为止所拥有的..如果有人可以提供帮助,我将非常感激,这样我就可以停止拉扯我的头发..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TweetSharp;
using System.Configuration;
using Hammock.Authentication.OAuth;
using System.Diagnostics;
namespace testtweet
{
public partial class Form1 : Form
{
//I already have these values not showing here for obvious reasons.
TwitterService service = new TwitterService("ConsumerKey", "ConsumerSecret");
public Form1()
{
InitializeComponent();
// Pass your credentials to the service
// Step 1 - Retrieve an OAuth Request Token
OAuthRequestToken requestToken = service.GetRequestToken();
// Step 2 - Redirect to the OAuth Authorization URL
Uri uri = service.GetAuthorizationUri(requestToken);
Form2 frm = new Form2(uri.ToString());
frm.Show();
OAuthRequestToken requestToken = service.GetRequestToken();
// Step 3 - Exchange the Request Token for an Access Token
string verifier = "123456"; // <-- This is input into your application by your user
OAuthAccessToken access = service.GetAccessToken(requestToken, verifier);
// Step 4 - User authenticates using the Access Token
service.AuthenticateWith(access.Token, access.TokenSecret);
IEnumerable<TwitterStatus> mentions = service.ListTweetsMentioningMe();
}
}
}
在我的 Form2 上
public Form2(string url)
{
InitializeComponent();
webBrowser1.Navigate(url);
}
,这就是我迷失的地方。如您所见,第 3 步正在等待 PIN 码。我该如何将其设置在那里?我有一个想法直接写在app.config中但是 我如何知道它何时生成?我应该制作第三个表单让用户在那里输入 pin 码吗?
Ok twitter might be great for social media but for a small app that I am trying to create just for fun has turned into a nightmare. I have searched everywhere and can't find a good explanation on how to use the api.
I am using the TweetSharp api and all I want to do is for user to allow my app and be able to post from the app to their twitter.
My problem comes when the app gives out a pin code for the user to type in...where would the user type it in at? Ok so this is what I have so far..if anyone can help i would be most greatful so I can stop pulling my hair..
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using TweetSharp;
using System.Configuration;
using Hammock.Authentication.OAuth;
using System.Diagnostics;
namespace testtweet
{
public partial class Form1 : Form
{
//I already have these values not showing here for obvious reasons.
TwitterService service = new TwitterService("ConsumerKey", "ConsumerSecret");
public Form1()
{
InitializeComponent();
// Pass your credentials to the service
// Step 1 - Retrieve an OAuth Request Token
OAuthRequestToken requestToken = service.GetRequestToken();
// Step 2 - Redirect to the OAuth Authorization URL
Uri uri = service.GetAuthorizationUri(requestToken);
Form2 frm = new Form2(uri.ToString());
frm.Show();
OAuthRequestToken requestToken = service.GetRequestToken();
// Step 3 - Exchange the Request Token for an Access Token
string verifier = "123456"; // <-- This is input into your application by your user
OAuthAccessToken access = service.GetAccessToken(requestToken, verifier);
// Step 4 - User authenticates using the Access Token
service.AuthenticateWith(access.Token, access.TokenSecret);
IEnumerable<TwitterStatus> mentions = service.ListTweetsMentioningMe();
}
}
}
on my Form2
public Form2(string url)
{
InitializeComponent();
webBrowser1.Navigate(url);
}
Here is where I am lost. As you see Step 3 is wating for the pin code..How would I set it in there? I had an idea to write directly in the app.config but
how do I know when it has been generated? Should I make a 3rd form to have the user input the pin code there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这就是我所得到的(在设计器中添加一个名为 webBrowser1 的网络浏览器)
然后像这样使用它:
so this is what I've got (add a webbrowser named webBrowser1 in the designer)
Then use it like this: