Created
March 25, 2016 13:52
-
-
Save oyakodon/06324af2a2535d429394 to your computer and use it in GitHub Desktop.
最初のツイートから何番目のツイートは何なのか?(関数のみ) / C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
static Status getNumOfTweet(Tokens t, int targetNum) | |
{ | |
// targetNum番目のツイートを返す(過去3200ツイート中で) | |
// [注意] 3200ツイート以上のロードが必要な場合、取得できる限り取得してツイートを返す。 | |
// なんか3200土10ぐらいの差があるが、そこら辺までしか取得できない。 | |
var me = t.Account.UpdateProfile(); | |
var targetCount = me.StatusesCount - targetNum; | |
if (targetCount == 0 ) | |
{ | |
// 最新のツイート | |
return me.Status; | |
} | |
int c = targetCount > 200 ? 1 : 0; | |
var lastId = me.Status.Id - 1; | |
while ( true ) | |
{ | |
var statuses = t.Statuses.UserTimeline(user_id => me.Id, count => 200, max_id => (lastId - 1)); | |
foreach ( var item in statuses ) | |
{ | |
lastId = item.Id; | |
c++; | |
if ( targetCount <= c ) break; | |
} | |
if ( statuses.Count < 20 ) | |
break; | |
if ( targetCount <= c ) break; | |
} | |
return t.Statuses.Show(id => lastId); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment