2014-05-06 38 views
0

我試圖使用LinqToTwitter發送推文。我的問題是,它幾乎從來沒有工作。我已經完成了三十次中的三次,而且通常是在我嘗試調試的時候。我認爲這可能與時間和身份驗證有關,但我不知道該怎麼做。該代碼運行沒有錯誤,但不生成鳴叫。LinqToTwitter狀態更新僅適用於

public static async Task SendTweetAsync(string text) 
    { 
     // Get the authorization credentials 
     var auth = GetCredentials(); 

     // Create the twitter context 
     var ctx = new TwitterContext(auth); 

     try 
     { 
      Status responseTweet = await ctx.TweetAsync(text); 
     } 
     catch (Exception e) { 
      throw e; 
     } 
    } 

    private static AspNetAuthorizer GetCredentials() 
    { 
     return new AspNetAuthorizer 
     { 
      CredentialStore = new InMemoryCredentialStore() 
      { 
       ConsumerSecret = "##########", 
       ConsumerKey = "##########", 
       OAuthToken = "##########", 
       OAuthTokenSecret = "##########", 
       UserID = ########## 
      } 
     }; 
    } 
+2

不要捕捉異常只是爲了重新拋出它。您正在清除堆棧跟蹤並添加任何附加值。 – Servy

+0

@Servy,謝謝。我會牢記這一點 - 這是一個臨時解決方案,雖然是一個很糟糕的解決方案。 –

+0

只是在最後一天我才遇到linqtotwitter streaming API的問題;一切工作正常之前與相同的二進制文件。不確定圖書館是否存在與某些Twitter更新或內容有關的問題。 –

回答

0

我不知道發生了什麼,這是這裏之前,由@JoeMayo答案,但爲我工作的事情是改變AspNetAuthorizerSingleUserAuthorizer

private static SingleUserAuthorizer GetCredentials() 
{ 
    return new SingleUserAuthorizer 
    { 
     CredentialStore = new InMemoryCredentialStore() 
     { 
      ConsumerSecret = "##########", 
      ConsumerKey = "##########", 
      OAuthToken = "##########", 
      OAuthTokenSecret = "##########", 
      UserID = ########## 
     } 
    }; 
} 

另外,我補充await auth.AuthorizeAsync();

var auth = GetCredentials(); 

await auth.AuthorizeAsync(); 

正如我所說,信貸應該真正去@JoeMayo,但他的回答已經一去不復返了。