簡體   English   中英

來自C#的Twitter Hello世界

[英]Hello World to Twitter from C#

幾天前,我發布了這個問題這個問題,詢問如何將“Hello World”發布到twitter。 我得到了有用的回應,這些推動了我的進一步發展,但我仍然迷失了。

我需要使用OAuth,因為(正如我所讀)使用用戶名和密碼很快就會被棄用。

我需要一個簡單的示例,例如使用字符串常量'Hello World!'更新狀態。

我的客戶端指定我必須使用C#。

絕對使用Linq2Twitter -

http://linqtotwitter.codeplex.com/

它的UpdateStatus方法有11個重載 - 整個實現非常好。 所以你的榜樣是:

var tweet = twitterCtx.UpdateStatus("Hello world");

我想在這里發布這篇文章,因為我花了很長時間才研究出來,而且我認為這是使用Linq2Twitter對Twitter進行Hello World的最低要求,因為OAuth是強制性的。 希望這對我這樣的人來說是有用的,他們最終會在這個頁面上發現它並沒有解決他們的問題。

using LinqToTwitter;
var auth = new SingleUserAuthorizer
{
    Credentials = new InMemoryCredentials
    {
        ConsumerKey = "yourConsumerKey",
        ConsumerSecret = "yourConsumerSecret",
        OAuthToken = "yourOAuthToken",
        AccessToken = "yourAccessToken"
    }
};

var service = new TwitterContext(auth);

var tweet = service.UpdateStatus("hello twitter");

您使用的API是什么? 你試過Twitterizer嗎? 它應該相對簡單。

我強烈建議您使用TweetSharp 它非常強大,支持您在上面指定的方案(使用OAuth進行身份驗證)。

我已經在一些寵物項目中使用它,我對它非常滿意。 下載附帶一個WPF示例應用程序,向您展示如何使用twitter的OAuth實現。

我沒有足夠的聲譽來評論zithrey,但我也同意,linq2twitter的入門文檔很痛,而且項目加載了錯誤使其無法運行。 希望這會幫助某人 - 它使用PIN授權

static void Main(string[] args)
{
    string ckey = "consumerkey";
    string csecret = "consumersecret";

    var auth = new PinAuthorizer()
    {
        Credentials = new InMemoryCredentials
        {
            ConsumerKey = ckey,
            ConsumerSecret = csecret
        },
        GoToTwitterAuthorization = pageLink => Process.Start(pageLink),
        GetPin = () =>
        {
            Console.WriteLine(
                "\nAfter authorizing this application, Twitter " +
                "will give you a 7-digit PIN Number.\n"
            );
            Console.Write("Enter the PIN number here: ");
            return Console.ReadLine();
        }
    };
    auth.Authorize();
    var twitterCtx = new TwitterContext(auth);
    twitterCtx.UpdateStatus("This status has been created from a C# console app!");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM