私はTwitter検索を行っており、地図上にプロットするために各ツイートの正確な場所を取得する必要があります。コアロケーションを設定しました。「ツイートを取得する」ためのコードは次のとおりです。
現在、テキストコンポーネントを取得するためにループしていますが、ツイートに付随するロケーションコンポーネントも取得する方法がわかりません。場所を抽出するためにループに追加した数行が下に表示されますが、空白/nullになっています。
•NSString*twitlocationをループ内の正しい場所に配置していますか?この収集された場所は、各ツイートの正しいテキストと結合しますか?つまり、個別の配列から呼び出します。つまり、objectAtIndex:0を実行すると、ツイート1のテキストとツイート1の場所が結合しますか?•twitterLocationのログがnullになるのはなぜですか。•配列に追加するためにNSStringに場所を配置するのは正しいですか、それとも別のオブジェクトにする必要がありますか?
参考までに
- すべてのオブジェクトは.hファイルで宣言されています-twitTextは正しく機能し、各ツイートのツイートテキストを取得できます-twitterLocationはNSMutableArrayです
ありがとう!
- (void)fetchTweets
{
AppDelegate *delegate = (AppDelegate*)[[UIApplication sharedApplication]delegate];
//NSLog(@"phrase carried over is %@", delegate.a);
// Do a simple search, using the Twitter API
TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:
[NSString stringWithFormat:@"http://search.twitter.com/search.json?q=%@", delegate.a]]
parameters:nil requestMethod:TWRequestMethodGET];
// Notice this is a block, it is the handler to process the response
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
if ([urlResponse statusCode] == 200)
{
// The response from Twitter is in JSON format
// Move the response into a dictionary and print
NSError *error;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&error];
//NSLog(@"Twitter response: %@", dict);
NSArray *results = [dict objectForKey:@"results"];
//Loop through the results
for (NSDictionary *tweet in results) {
// Get the tweet
NSString *twittext = [tweet objectForKey:@"text"];
//looping through to also get the location of each tweet
NSString *twitlocation = [tweet objectForKey:@"location"];
// Save the tweet to the twitterText array
[_twitterText addObject:twittext];
//adding the twitlocation to the location array
[twitterLocation addObject:twitlocation];
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
NSLog(@"MY ************************LOCATION************** %@", twitterLocation);
}
else
NSLog(@"Twitter error, HTTP response: %i", [urlResponse statusCode]);
}];
}