【问题标题】:Twitter status update: set source (C#)Twitter状态更新:设置源(C#)
【发布时间】:2011-08-20 19:54:19
【问题描述】:

我正在使用下面的简单代码更新我的用户的 Twitter 状态。我的问题是此代码产生的 Twitter 更新被表示为“....以前 来自 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
    }
}

【问题讨论】:

  • 使用 REST API 似乎不可能做到这一点。我仍在搜索并使用 cURL 命令行对其进行测试,但不,不工作

标签: c# twitter


【解决方案1】:

获取“来自 MyApp”的唯一方法是使用 OAuth 并通过您的 Twitter 开发人员帐户进行设置。您曾经能够随请求发送 HTTP POST 参数(来源),但它已被弃用。

【讨论】:

    【解决方案2】:

    只是一个小建议,您可能想看看 TweetSharp 库,它可以让您的生活更轻松,而不是在 REST API 级别上胡闹。

    如果您不喜欢 TweetSharp 的外观,Twitter 有一个您可以用于 C# here 的其他库的列表。

    【讨论】:

      【解决方案3】:

      请在此处注册您的应用 http://twitter.com/apps/new

      一旦他们批准,您就可以传递一个参数“来源”来将您的推文标记为来自您的应用程序。

      【讨论】:

        【解决方案4】:

        您必须注册您的APP才能更改此名称。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2012-03-13
          • 2016-03-12
          • 2012-01-11
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多