OpenTweenのfork
修订版 | 9a5be64af84ae3ca4bd27282c0657ca6b8ea27cf (tree) |
---|---|
时间 | 2012-06-17 22:38:54 |
作者 | re4k <re4k@re4k...> |
Commiter | re4k |
発言のRetweet回数を取得できるようにした
@@ -1293,62 +1293,55 @@ namespace OpenTween | ||
1293 | 1293 | |
1294 | 1294 | public string GetStatus_Retweeted_Count(long StatusId, ref int retweeted_count) |
1295 | 1295 | { |
1296 | - if (MyCommon._endingFlag) return ""; | |
1297 | - | |
1298 | 1296 | if (Twitter.AccountState != MyCommon.ACCOUNT_STATE.Valid) return ""; |
1299 | 1297 | |
1298 | + if (MyCommon._endingFlag) return ""; | |
1299 | + | |
1300 | 1300 | HttpStatusCode res = HttpStatusCode.BadRequest; |
1301 | 1301 | var content = ""; |
1302 | 1302 | |
1303 | - retweeted_count = 0; | |
1304 | - | |
1305 | - // 注:dev.twitter.comに記述されているcountパラメータは間違い。100が正しい | |
1306 | - for (int i = 1; i <= 100; i++) | |
1303 | + try | |
1307 | 1304 | { |
1308 | - try | |
1309 | - { | |
1310 | - res = twCon.Statusid_retweeted_by_ids(StatusId, 100, i, ref content); | |
1311 | - } | |
1312 | - catch(Exception ex) | |
1313 | - { | |
1314 | - return "Err:" + ex.Message; | |
1315 | - } | |
1305 | + res = twCon.ShowStatuses(StatusId, ref content); | |
1306 | + } | |
1307 | + catch (Exception ex) | |
1308 | + { | |
1309 | + return "Err:" + ex.Message; | |
1310 | + } | |
1311 | + switch (res) | |
1312 | + { | |
1313 | + case HttpStatusCode.OK: | |
1314 | + Twitter.AccountState = MyCommon.ACCOUNT_STATE.Valid; | |
1315 | + break; | |
1316 | + case HttpStatusCode.Unauthorized: | |
1317 | + Twitter.AccountState = MyCommon.ACCOUNT_STATE.Invalid; | |
1318 | + return Properties.Resources.Unauthorized; | |
1319 | + case HttpStatusCode.BadRequest: | |
1320 | + return "Err:API Limits?"; | |
1321 | + case HttpStatusCode.Forbidden: | |
1322 | + return "Err:protected user's tweet"; | |
1323 | + default: | |
1324 | + return "Err:" + res.ToString() + "(" + MethodBase.GetCurrentMethod().Name + ")"; | |
1325 | + } | |
1316 | 1326 | |
1317 | - switch (res) | |
1318 | - { | |
1319 | - case HttpStatusCode.OK: | |
1320 | - try | |
1321 | - { | |
1322 | - var ids = MyCommon.CreateDataFromJson<Int64[]>(content); | |
1323 | - retweeted_count += ids.Length; | |
1324 | - if (ids.Length < 100) goto exit_for; | |
1325 | - } | |
1326 | - catch (SerializationException ex) | |
1327 | - { | |
1328 | - retweeted_count = -1; | |
1329 | - MyCommon.TraceOut(ex.Message + Environment.NewLine + content); | |
1330 | - return "Err:Json Parse Error(DataContractJsonSerializer)"; | |
1331 | - } | |
1332 | - catch (Exception ex) | |
1333 | - { | |
1334 | - retweeted_count = -1; | |
1335 | - MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content); | |
1336 | - return "Err:Invalid Json!"; | |
1337 | - } | |
1338 | - break; | |
1339 | - case HttpStatusCode.BadRequest: | |
1340 | - retweeted_count = -1; | |
1341 | - return "Err:API Limits?"; | |
1342 | - case HttpStatusCode.Unauthorized: | |
1343 | - retweeted_count = -1; | |
1344 | - Twitter.AccountState = MyCommon.ACCOUNT_STATE.Invalid; | |
1345 | - return Properties.Resources.Unauthorized; | |
1346 | - default: | |
1347 | - retweeted_count = -1; | |
1348 | - return "Err:" + res.ToString() + "(" + MethodBase.GetCurrentMethod().Name + ")"; | |
1349 | - } | |
1327 | + TwitterDataModel.Status status; | |
1328 | + try | |
1329 | + { | |
1330 | + status = MyCommon.CreateDataFromJson<TwitterDataModel.Status>(content); | |
1331 | + } | |
1332 | + catch (SerializationException ex) | |
1333 | + { | |
1334 | + MyCommon.TraceOut(ex.Message + Environment.NewLine + content); | |
1335 | + return "Json Parse Error(DataContractJsonSerializer)"; | |
1336 | + } | |
1337 | + catch (Exception ex) | |
1338 | + { | |
1339 | + MyCommon.TraceOut(ex, MethodBase.GetCurrentMethod().Name + " " + content); | |
1340 | + return "Invalid Json!"; | |
1350 | 1341 | } |
1351 | - exit_for: | |
1342 | + int tmp; | |
1343 | + if (int.TryParse(status.RetweetCount, out tmp)) | |
1344 | + retweeted_count = tmp; | |
1352 | 1345 | return ""; |
1353 | 1346 | } |
1354 | 1347 |