質問

以下の簡単なコードを使用して、ユーザーのTwitterステータスを更新しています。私の問題は、このコードによるTwitterの更新が" .... ago from API "と表示されることです。 「API」を制御できるようにしたいカスタム名を言う部分。どうすればいいですか?できれば以下のコードの変更を使用してください...

ありがとう

/*
 * A function to post an update to Twitter programmatically
 * Author: Danny Battison
 * Contact: gabehabe@hotmail.com
 */

/// <summary>
/// Post an update to a Twitter acount
/// </summary>
/// <param name="username">The username of the account</param>
/// <param name="password">The password of the account</param>
/// <param name="tweet">The status to post</param>
public static void PostTweet(string username, string password, string tweet)
{
    try
    {
        // encode the username/password
        string user = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(username + ":" + password));
        // determine what we want to upload as a status
        byte[] bytes = System.Text.Encoding.ASCII.GetBytes("status=" + tweet);
        // connect with the update page
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://twitter.com/statuses/update.xml");
        // set the method to POST
        request.Method = "POST";
        request.ServicePoint.Expect100Continue = false; // thanks to argodev for this recent change!
        // set the authorisation levels
        request.Headers.Add("Authorization", "Basic " + user);
        request.ContentType = "application/x-www-form-urlencoded";
        // set the length of the content
        request.ContentLength = bytes.Length;

        // set up the stream
        Stream reqStream = request.GetRequestStream();
        // write to the stream
        reqStream.Write(bytes, 0, bytes.Length);
        // close the stream
        reqStream.Close();
    }
    catch (Exception ex) 
    {
        // Log the error
    }
}
役に立ちましたか?

解決

「MyAppから」を取得する唯一の方法OAuthを使用して、Twitter開発者アカウントでセットアップすることです。以前はリクエスト(ソース)でHTTP POSTパラメーターを送信できましたが、それは非推奨です。

他のヒント

ちょっとした提案として、 TweetSharp ライブラリをご覧ください。 、REST APIレベルで自分をいじくり回すよりもあなたの人生を楽にすることができます。

Twitterには、C#こちらで使用できる他のライブラリのリストがあります。 TweetSharpの外観が気に入らない。

ここでアプリを登録してください http://twitter.com/apps/new

承認されたら、「source」パラメーターを渡して、アプリからツイートとしてマークを付けることができます。

この記事を読むことをお勧めします:ツイートのコーディング by James Devlin。

この名前を変更するには、APPを登録する必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top