2016-04-22 27 views
2

我想學習使用tweetinvi將C#連接到Twitter。C#tweetinvi代碼408

我沒有問題,而與Twitter KeyTwitter Token

連接,然後調試我的代碼,發現在User.GetAuthenticatedUser()

null值不過,我已經委託我自己的Twitter帳戶的Twitter的應用服務。爲什麼User.GetAuthenticatedUser()返回Null值?

我得到了,而試圖將錯誤傳遞到Message Box enter image description here

如何解決這個下面的圖片?

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Data; 
using System.Drawing; 
using System.Linq; 
using System.Text; 
using System.Threading.Tasks; 
using System.Windows.Forms; 
using Tweetinvi; 


namespace Twitdesk 
{ 
    public partial class Form1 : Form 
    { 
     Cl_Tweetinvi twitinvi; 
     Command cmd = new Command(); 

     public Form1() 
     { 
      InitializeComponent(); 
      twitinvi = new Cl_Tweetinvi(); 
      var AuthenticatedUser = User.GetAuthenticatedUser(); 
      if(AuthenticatedUser == null) 
      { 
       var latestException = ExceptionHandler.GetLastException(); 
       MessageBox.Show(latestException.ToString()); 
       Application.Exit(); 
      } 
      else 
      { 
       var settings = AuthenticatedUser.GetAccountSettings(); 
      } 

      var tweets = Timeline.GetHomeTimeline();    
      this.Text = cmd.title; 
      MessageBox.Show("done"); 
     } 
    } 
} 

enter image description here

回答

1

的問題來自於事實,你尚未初始化憑據。

在執行任何操作之前,您需要先撥打Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");

當您調用此行時,任何操作都將使用這些憑證。

請快速瀏覽wiki瞭解更多信息。或者讓我知道你是否仍然遇到任何問題。

雖然問題可能不同,因爲錯誤消息似乎表明您有超時問題。通常,身份驗證問題會返回401異常。

+0

嗨,我做了一些更新,你的代碼已經寫好了。我想知道爲什麼'AuthenticatedUser'變成'null' – Cignitor

+0

現在它工作嗎? – Linvi

+0

nope,我不知道爲什麼'AuthenticatedUser'返回'Null',因爲有我自己的Twitter帳戶使用我的twitter應用程序。 – Cignitor