2014-09-02 3 views
0

나는 사용자 즐겨 찾기 세트를 얻기위한 코드를 작성했으나 명확하지 않은 것은 사용자가 처음으로 즐겨 찾기 세트를 얻는 데 페이지/커서를 사용하여이를 수행 할 수있는 방법입니다. ? 서 값은 항상 0이고 max/since ID은 널입니다. LinqToTwitter를 사용하여 이것을 실현하는 방법이 있습니까?LinqToTwitter. 즐겨 찾기 - 모두 얻으십시오

답변

2

즐겨 찾기의 경우, SinceID/MaxID로 타임 라인을 탐색해야합니다. 여기 예가 있습니다 :

static async Task ShowFavoritesAsync(TwitterContext twitterCtx) 
    { 
     const int PerQueryFavCount = 200; 

     // set from a value that you previously saved 
     ulong sinceID = 1; 

     var favsResponse = 
      await 
       (from fav in twitterCtx.Favorites 
       where fav.Type == FavoritesType.Favorites && 
         fav.Count == PerQueryFavCount 
       select fav) 
       .ToListAsync(); 

     if (favsResponse == null) 
     { 
      Console.WriteLine("No favorites returned from Twitter."); 
      return; 
     } 

     var favList = new List<Favorites>(favsResponse); 

     // first tweet processed on current query 
     ulong maxID = favList.Min(fav => fav.StatusID) - 1; 

     do 
     { 
      favsResponse = 
       await 
        (from fav in twitterCtx.Favorites 
        where fav.Type == FavoritesType.Favorites && 
          fav.Count == PerQueryFavCount && 
          fav.SinceID == sinceID && 
          fav.MaxID == maxID 
        select fav) 
        .ToListAsync(); 

      if (favsResponse == null || favsResponse.Count == 0) break; 

      // reset first tweet to avoid re-querying the 
      // same list you just received 
      maxID = favsResponse.Min(fav => fav.StatusID) - 1; 
      favList.AddRange(favsResponse); 

     } while (favsResponse.Count > 0); 

     favList.ForEach(fav => 
     { 
      if (fav != null && fav.User != null) 
       Console.WriteLine(
        "Name: {0}, Tweet: {1}", 
        fav.User.ScreenNameResponse, fav.Text); 
     }); 

     // save this in your db for this user so you can set 
     // sinceID accurately the next time you do a query 
     // and avoid querying the same tweets again. 
     ulong newSinceID = favList.Max(fav => fav.SinceID); 
    } 

나는 Twitter Timeline에서 작업하는 방법을 설명하는 블로그 게시물을 작성했습니다. 그것은 트위터에 LINQ의 이전이 아닌 비동기 버전 용으로 작성하지만, 개념은 동일하게 유지되었다

Twitter's Working with Timelines Documentation

:

Working with Timelines with LINQ to Twitter

이 좋은 읽기입니다 트위터의 지침을 기반으로

관련 문제