2017-03-02 54 views
1

我試圖從Twitter的鳴叫,但它不跟我合作,讓鳴叫,這裏是代碼:通過LinqToTwitter

var auth = new SingleUserAuthorizer 
      { 

       CredentialStore = new SingleUserInMemoryCredentialStore() 
       { 

        ConsumerKey = ConfigurationManager.AppSettings["***"], 
        ConsumerSecret = ConfigurationManager.AppSettings["***"], 
        AccessToken = ConfigurationManager.AppSettings["***"], 
        AccessTokenSecret = ConfigurationManager.AppSettings["***"] 

       } 

      }; 

var context = new TwitterContext(auth); 
var tweets = 
    from tw in context.Status 
    where 
     tw.Type == StatusType.User && 
     tw.ScreenName == "***" 
    select tw; 
// handle exceptions, twitter service might be down 
try 
{ 
    // map to list 
    tweets 
     .Take(3) 
     .Select(t => 
      new Tweets 
      { 
       //Username = t.ScreenName, 
       //FullName = t.User.Name, 
       TweetText = t.Text, 
       //FormattedText = ParseTweet(t.Text) 
      }) 
     .ToList(); 
} 
catch (Exception) { } 
每次

當我試圖讀取鳴叫它失敗,例外是

LinqToTwitter.TwitterQueryException: Bad Authentication data 

但我確定憑證是正確的。

也有可能讀取另一個Twitter帳戶的帖子?像公司帳戶或慶祝帳戶?

回答

1

的LINQ to Twitter是異步,所以你應該改變你的查詢是這樣的:

var tweets = 
    await 
    (from tw in context.Status 
    where 
     tw.Type == StatusType.User && 
    tw.ScreenName == "***" 
    select tw) 
    .ToListAsync(); 

此外,實例驗證後打一個斷點,並檢查證書,以確保你正確填充它們。

+0

謝謝你對我的作品:) – Ateeq