我基本上只需要一个表格视图,它显示来自 tableviewcontroller 中 @username 或 #hashtag 的最近推文。不需要发布推文或类似的东西。
目前我使用MGTwitterEngine
它很复杂,只获取与用户名相关的推文而不是 hastags。
我找到了这个教程,但是大部分代码没有解释,也没有源代码。
也找到这个,但似乎http://search.twitter.com/search?q=%23
+ #hashtag 返回nil
数据
还看到这个问题为 ARC 编辑了代码并使用http://search.twitter.com/search.json?q=%23epicwinning+OR+%40charliesheen
链接来获取数据
#import <Foundation/Foundation.h>
@protocol latestTweetsDelegate
- (void)returnedArray:(NSArray*)tArray;
@end
@interface latestTweets : NSObject
{
NSMutableData *responseData;
NSMutableArray *resultsArray;
id<latestTweetsDelegate> delegate;
}
@property (nonatomic, strong) NSMutableArray *resultsArray;
@property (strong,nonatomic) id<latestTweetsDelegate> delegate;
- (id)initWithTwitterURL:(NSString *)twitterURL;
@end
#import "latestTweets.h"
#import "SBJson.h"
@implementation latestTweets
@synthesize resultsArray, delegate;
- (id)initWithTwitterURL:(NSString *)twitterURL
{
self = [super init];
if (self) {
responseData = [NSMutableData data];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:twitterURL]];
[[NSURLConnection alloc] initWithRequest:request delegate:self];
}
return self;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(@"Connection failed: %@", [error description]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSArray *newData = [responseString JSONValue];
[self.delegate returnedArray:newData];
}
@end
我打电话
latestTweets *lt = [[latestTweets alloc] initWithTwitterURL:@"http://search.twitter.com/search.json?q=%23epicwinning+OR+%40charliesheen"];
lt.delegate = self;
返回结果数组:-[TwitterFeed returnedArray:]: unrecognized selector sent to instance
是否有任何简单的教程或代码示例可以同时获取用户名和主题标签推文?
或者
有没有办法用 获取主题标签MGTwitterEngine
?