문제

아래의 간단한 코드를 사용하여 사용자의 트위터 상태를 업데이트하고 있습니다. 내 문제는이 코드로 인한 트위터 업데이트가 ".... wecon으로 표시된다는 것입니다. 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 매개 변수를 보낼 수 있었지만 이후 더 이상 사용되지 않았습니다.

다른 팁

작은 제안만으로, 당신은 트위터 샤프 라이브러리는 나머지 API 수준에서 자신을 쫓아내는 대신 인생을 더 쉽게 만들 수 있습니다.

Twitter에는 C#에 사용할 수있는 다른 라이브러리 목록이 있습니다. 여기, 당신이 트위터 샤프의 모습을 좋아하지 않는다면.

여기에 앱을 등록하십시오http://twitter.com/apps/new

그들이 승인하면 매개 변수 '소스'를 전달하여 트윗을 앱에서 표시 할 수 있습니다.

이 기사를 읽고 싶을 수도 있습니다. 트윗 코딩 제임스 데플린.

이 이름을 변경하려면 앱을 등록해야합니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top