我的客戶希望我使用.NET發佈到Twitter,並建議使用C#。將「Hello World」發佈到.NET應用程序的推文
問:如何在Twitter上使用C#發佈「Hello World」?
This post提到一個叫做twitterizer的庫。沒有使用第三方庫的原生方式嗎? (也許不是,因爲身份驗證是要求之一)。
我的客戶希望我使用.NET發佈到Twitter,並建議使用C#。將「Hello World」發佈到.NET應用程序的推文
問:如何在Twitter上使用C#發佈「Hello World」?
This post提到一個叫做twitterizer的庫。沒有使用第三方庫的原生方式嗎? (也許不是,因爲身份驗證是要求之一)。
只要使用該包裝來實現對Twitter的API:
https://github.com/danielcrenna/tweetsharp
var twitter = FluentTwitter.CreateRequest()
.AuthenticateAs("USERNAME", "PASSWORD")
.Statuses().Update("Hello World!")
.AsJson();
var response = twitter.Request();
來源:http://code-inside.de/blog-in/2009/04/23/howto-tweet-with-c/
是的,您可以在沒有任何第三方庫的情況下執行此操作。請參閱我的IronPython sample發佈在IronPython Cookbook網站上,該網站會向您顯示如何。即使你在IronPython的,應該讓你開始下面,易反覆移植到C#代碼的主要部分不計劃:
ServicePointManager.Expect100Continue = False
wc = WebClient(Credentials = NetworkCredential(username, password))
wc.Headers.Add('X-Twitter-Client', 'Pweeter')
form = NameValueCollection()
form.Add('status', status)
wc.UploadValues('http://twitter.com/statuses/update.xml', form)
基本上,這確實一個HTTP POST到http://twitter.com/statuses/update.xml用單名爲status
的HTML FORM字段,其中包含由username
(和password
)標識的帳戶的狀態更新文本。
今天工作正常,但當Twitter關閉下個月的基本身份驗證時,它將停止工作。 – 2010-05-18 20:40:26
+1用於實際理解問題(使用API進行處理)。 – 2010-05-19 18:40:08
我創建準確說明如何設置內部的Twitter的應用程序,使用的NuGet安裝的API庫,從用戶接受一個訪問令牌,並張貼在該用戶的代表的視頻教程:
視頻: http://www.youtube.com/watch?v=TGEA1sgMMqU
教程:http://www.markhagan.me/Samples/Grant-Access-And-Tweet-As-Twitter-User-ASPNet
如果你不想離開這個頁面:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Twitterizer;
namespace PostFansTwitter
{
public partial class twconnect : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
var oauth_consumer_key = "gjxG99ZA5jmJoB3FeXWJZA";
var oauth_consumer_secret = "rsAAtEhVRrXUTNcwEecXqPyDHaOR4KjOuMkpb8g";
if (Request["oauth_token"] == null)
{
OAuthTokenResponse reqToken = OAuthUtility.GetRequestToken(
oauth_consumer_key,
oauth_consumer_secret,
Request.Url.AbsoluteUri);
Response.Redirect(string.Format("http://twitter.com/oauth/authorize?oauth_token={0}",
reqToken.Token));
}
else
{
string requestToken = Request["oauth_token"].ToString();
string pin = Request["oauth_verifier"].ToString();
var tokens = OAuthUtility.GetAccessToken(
oauth_consumer_key,
oauth_consumer_secret,
requestToken,
pin);
OAuthTokens accesstoken = new OAuthTokens()
{
AccessToken = tokens.Token,
AccessTokenSecret = tokens.TokenSecret,
ConsumerKey = oauth_consumer_key,
ConsumerSecret = oauth_consumer_secret
};
TwitterResponse<TwitterStatus> response = TwitterStatus.Update(
accesstoken,
"Testing!! It works (hopefully).");
if (response.Result == RequestResult.Success)
{
Response.Write("we did it!");
}
else
{
Response.Write("it's all bad.");
}
}
}
}
}
阿喀琉斯,謝謝你的回答! – 2010-05-21 13:40:14
Broken Link http://tweetsharp.codeplex.com/ – jth41 2014-03-23 03:24:54
看起來現在住在這裏:https://github.com/Yortw/tweetmoasharp – 2016-08-26 02:09:33