2009-08-01 5 views
1

아래의 간단한 코드를 사용하여 내 사용자의 트위터 상태를 업데이트하고 있습니다. 내 문제는이 코드의 결과 인 Twitter 업데이트가 "from API"으로 표시된다는 것입니다. 사용자 정의 이름을 말하기 위해 "API"부분을 제어 할 수 있기를 원합니다. 내가 어떻게 해? 제임스 데블린에 의해 Coding the Tweet : 바람직트위터 상태 업데이트 : 소스 설정 (C#)

감사

/* 
* A function to post an update to Twitter programmatically 
* Author: Danny Battison 
* Contact: [email protected] 
*/ 

/// <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 
    } 
} 
+0

REST API를 사용하는 것이 불가능한 것 같습니다. 나는 여전히 그것을 찾고 cURL 커맨드 라인을 사용하여 테스트하고 있지만, 안되는 것은 작동하지 않는다. –

답변

3

"MyApp에서"얻을 수있는 유일한 방법은 OAuth를 사용하고 Twitter 개발자 계정을 통해 설정하는 것입니다. 당신은 요청 (소스)과 함께 HTTP POST 매개 변수를 보낼 수 있었지만 그 이후에는 더 이상 사용되지 않습니다.

0
이 문서를 읽어보십시오

... 아래의 코드로 변경을 사용하여.

1

작은 제안으로, TweetSharp 라이브러리를 살펴보고 싶다면 REST API 레벨에서 자신보다 더 편하게 생활 할 수 있습니다.

TweetSharp의 모양이 마음에 들지 않으면 트위터에 C# here에 사용할 수있는 다른 라이브러리 목록이 있습니다.

0

이 이름을 변경하려면 APP를 등록해야합니다. 그들은 당신이 당신의 트윗 앱에서로 표시 얻을 수있는 매개 변수 '소스'를 전달할 수 있습니다 승인되면