現在、iOS アプリケーションで Twitter からのツイートを解析しています。現在、私のアプリは API 呼び出しを使用して検索を実行できsearch.twitter.com/search.json?...
、アプリはこれらのツイートを解析して、各ツイートに必要なすべてのデータを選択できます。現在、ユーザーのタイムラインを取得しようとしている段階ですが、ユーザーのタイムライン API 呼び出しから返されたオブジェクトを解析する安定した方法が見つからないようです。
検索機能 ( https://dev.twitter.com/docs/api/1/get/searchvalueForKey:(@"results")
の下部にある返されるオブジェクトの例) を使用すると、次のように、これらすべての結果を選択してループすることで解析できます。
//jSONText is the returned result from the API in NSDictionary format
NSArray *resultTweetsJSON = [jSONText valueForKey:(@"results")];
for (int tweetIndex=0; tweetIndex<[resultTweetsJSON count]; tweetIndex++) {
//Loop through and pull out raw tweet content for a specific tweet
NSString *rawTweetContent = [resultTweetsJSON objectAtIndex:tweetIndex];
//Build a custom tweet object using that content
Tweet *singleTweet = [[Tweet alloc] initWithResultsContent:rawTweetContent];
}
私は同じまたは類似のことを実行できることを望んでいましたが、タイムラインから返されたデータで使用する適切なキーが見つからないようです (サンプルは、https://dev.twitter. com/docs/api/1/get/statuses/user_timeline )。
ご覧のとおり、結果セットには、クエリを実行できる適切user_time
な " " キーが含まれていません。results
Twitter APIの呼び出しからデータを簡単に選択して解析し、Get/Statuses/User_Timeline
それを NSArray に変換して、ツイートをループして抽出できるようにするにはどうすればよいでしょうか? オンラインのすべてが古い手法を使用しているようです。このチュートリアルを見つけましたが、Twitter からの応答を NSDictionary オブジェクトではなく NSData オブジェクトとして受け取っているようです。NSDictionary が最新の方法だと思います。
ここに私がうまくいくかもしれないと思ったものがあります:
//No valueForKey to use, so perhaps use ""?
NSArray *timeline = [jSONText valueForKey:(@"")];
for (int i=0; i<[timeline count]; i++) {
//Looping through each "object" of the timeline, grab the tweet content then fill user content
//Grab the "user" object from the timeline object we're looking at
NSString *rawUserContent = [[timeline objectAtIndex:i] valueForKey:(@"user")];
//NSString *rawUserContent = [timeline valueForKey:(@"user")]; - Maybe this?
//Do whatever else I need to do here...
}