2013-05-07 76 views
0

我一直在使用Linq to Twitter進行Twitter API 1.1的OAuth身份驗證。 我設置我的憑據,然後將它們傳遞給Linq到Twitter,它聲明我isAuth返回true。但是,在運行時,我收到215「錯誤驗證數據」錯誤。有沒有其他人有這個問題?Linq to Twitter身份驗證但得到215「錯誤身份驗證數據」

這裏是如果其他事物,說明我的授權:

 if (auth == null || !auth.IsAuthorized) 
     { 

     } 
     // If Twitter Authorizes Application 
     if (auth.IsAuthorized && i == 1) 
     { 

      HttpClient client = new HttpClient(); 
      HttpResponseMessage response = await client.GetAsync(new Uri("https://api.twitter.com/1.1/search/tweets.json?q=%23freebandnames&since_id=24012619984051000&max_id=250126199840518145&result_type=mixed&count=4")); 
      string json = await response.Content.ReadAsStringAsync(); 

      JObject obj = JObject.Parse(json); 
      var jsonResults = obj["results"]; 

      await JsonConvert.DeserializeObjectAsync<List<Tweet>>(jsonResults.ToString()); 

     } 

我能夠進入代碼auth.IsAtuhorized部分,但響應返回一個215錯誤。另外我知道我的URI是正確的,因爲我直接從Twitter API 1.1示例頁面複製它以測試呼叫。在此先感謝

回答

0

您正在使用授權人,但是然後你不使用LINQ to Twitter查詢。您正在使用HttpClient,並且兩個API之間沒有關係。下面是如何使用LINQ進行搜索,Twitter的一個例子:

var srch = 
     (from search in twitterCtx.Search 
     where search.Type == SearchType.Search && 
       search.Query == "LINQ to Twitter" && 
       search.Count == 7 
     select search) 
     .SingleOrDefault(); 

    Console.WriteLine("\nQuery: {0}\n", srch.SearchMetaData.Query); 
    srch.Statuses.ForEach(entry => 
     Console.WriteLine(
      "ID: {0, -15}, Source: {1}\nContent: {2}\n", 
      entry.StatusID, entry.Source, entry.Text)); 

您可以訪問LINQ to Twitter Search Documentation的可用參數的更多信息。

更新,這裏是一個異步採樣:

(from search in twitterCtx.Search 
    where search.Type == SearchType.Search && 
      search.Query == QueryTextBox.Text 
    select search) 
    .MaterializedAsyncCallback(asyncResponse => 
     Dispatcher.BeginInvoke(() => 
     { 
      if (asyncResponse.Status != TwitterErrorStatus.Success) 
      { 
       MessageBox.Show("Error during query: " + asyncResponse.Exception.Message); 
       return; 
      } 

      Search search = asyncResponse.State.SingleOrDefault(); 
      var tweets = 
       (from status in search.Statuses 
       select new Tweet 
       { 
        UserName = status.User.Identifier.ScreenName, 
        Message = status.Text, 
        ImageSource = status.User.ProfileImageUrl 
       }) 
       .ToList(); 

      SearchListBox.ItemsSource = tweets; 
     })); 
+0

謝謝喬。還有一個問題,而不是寫結果控制檯使用寫行我試圖將它們添加到列表。我已經嘗試使用基本的Foreach循環和srch.Statues.Foreach方法,但它一直說它不包含'ForEach'的方法 – Dadles 2013-05-08 14:37:38

+0

Never Mind能夠通過執行基本的For循環來解決您的問題幫幫我。將在代碼完成後張貼完成的答案 – Dadles 2013-05-08 16:18:17

+0

Joe。還有一個問題是無論如何要使用異步並等待搜索功能來提高性能? – Dadles 2013-05-09 13:24:53