2012-03-04 3 views
1

분명히 알 수는 있지만 미안하지만 대답을 찾을 수 없습니다. 나는 상태를 게시하고 싶다. 내가 알 수있는 건이 두 줄 뿐이야. 로그인 방법을 알 수 없습니다. 그것의 사용자/암호 또는 API 키를 사용하는 경우 상관 없어.지인에게 linq으로 어떻게 로그인합니까?

var twitterCtx = new TwitterContext(); 
var tweet = twitterCtx.UpdateStatus(@"test text"); 

저는 이것을 콘솔 앱으로하고 있습니다.

+0

많은 고통과 다양한 .NET 트위터 래퍼 후에 나는 nuget 패키지 관리자 인 http://visualstudiogallery.msdn.microsoft.com/27077b70-9dad-4c64-adcf-c7cf6bc9970c를 가져 와서 거기에서 tweetsharp를 설치했습니다. –

+0

Linq-to-twitter? 코드에는 140 자만 허용됩니까? 대신 TwitterContext (UsernamePasswordAuthorization) 생성자를 사용해보십시오. –

+0

@HansPassant : 그것에 관한 문서가 없습니다. 그러나 나는 tweetsharp와 mono/linux로 작업하고있다. –

답변

7

내 영어에 대해 불쌍하지만 당신을 도울 것입니다!

먼저 자신의 트위터 카운트의 사용자와 비밀번호로 인증을 생성해야합니다. 당신은 당신의 이름에 놓여져 aplicattion을 등록 여기이 페이지 http://dev.twitter.com에 트위터에 aplication을 등록해야하는 또 다른 방법이있다

UsernamePasswordAuthorization cxauthentication = new UsernamePasswordAuthorization(); 
ctxauthenticatin.UserName = userName; // Put in your Twitter Account 
ctxauthenticatin.Password = password; // and password 
ctxauthenticatin.AllowUIPrompt = false; 
ctxauthenticatin.SignOn(); 

var ctxTwitterContext = new TwitterContext(ctxauthentication); 
ctxTwitterContext.UpdateStatus("test text"); 

, 웹의 direccion은, 그들은 당신에게 ConsumerKey, ConsumerSecert을주고 액세스 토큰을 생성하는 경우에는 AccessToken 및 AccessTokenSecret을 제공합니다. Remenber 설정으로 이동하여 직접 메시지 읽기, 쓰기 및 액세스 옵션을 선택합니다. 그런 다음 AccessToken을 생성하십시오. 코드에서이 가진 좋아 당신은 이런 식으로 뭔가를 할 :

public partial class _Default : System.Web.UI.Page 
{ 
private WebAuthorizer auth; 
private TwitterContext twitterCtx; 

protected void Page_Load(object sender, EventArgs e) 
{ 
    IOAuthCredentials credentials = new SessionStateCredentials(); 

    if (credentials.ConsumerKey == null || credentials.ConsumerSecret == null) 
    { 
     credentials.ConsumerKey = "Here put your ConsumerKey"; 
     credentials.ConsumerSecret = "Here put your ConsumerSecret" 
    } 

    auth = new WebAuthorizer 
    { 
     Credentials = credentials, 
     PerformRedirect = authUrl => Response.Redirect(authUrl) 
    }; 
     if (!Page.IsPostBack) 
    { 
     auth.CompleteAuthorization(Request.Url); 
    } 
    twitterCtx = new TwitterContext(auth); 
} 
protected void authorizeTwitterButton_Click(object sender, EventArgs e) 
{ 
    auth.BeginAuthorization(Request.Url); 
} 

보호 무효 SendTweet_Click (개체 보낸 사람, EventArgs입니다 전자) { twitterCtx.UpdateStatus ("내 테스트 트윗");
}

Easy !! 좋아, 어떻게 작동하는지! 먼저 authorizeTwitterButton 버튼을 클릭하면 트위터 계정에 대한 권한 부여가 시작되고 응용 프로그램에 권한을 부여한 트위터에 로그인 한 다음 새 윈도우가 열리고 트위터가 자격 증명이있는 페이지로 리디렉션되므로 보내기 버튼을 클릭하면 당신은 새로운 트윗을 게시합니다!

시작 및 완료 인증 방법을 사용하지 않아도되는 또 다른 방법이 있습니다. 여기서 모든 자격 증명을 직접 소개합니다. 예 :

var auth = new SingleUserAuthorizer 
{ 
      Credentials = new InMemoryCredentials 
      { 
       ConsumerKey = "your ConsumerKey", 
       ConsumerSecret = "Your consumerSecret", 
       OAuthToken = "your AccessToken", 
       AccessToken = "your AccessTokenSecret"] 
      } 
     }; 
var ctxTwitterContext = new TwitterContext(auth); 
ctxTwitterContext.UpdateStatus("test text"); 

Ok! 내 anwser 도움이되기를 바랍니다 !! 자세한 내용은 http://linqtotwitter.codeplex.com/ 의 설명서를 참조하십시오. 당신이 내 anwser을 좋아한다면 그냥 클릭하십시오! jaja

+0

이것은 오래된 질문이며, 제가 이미 뭔가를 얻었다고 말했습니다. 하지만 +1 어쨌든 –

+0

나는 tweetsharp가 더 좋아. https://github.com/danielcrenna/tweetsharp#authenticating-a-client-application-ie-desktop. 앱 소비자 키/비밀 키를 입력하면 사용자가 자신의 계정을 인증 할 수있는 작은 코드가 필요 없습니다. –