我基本上只需要一个表视图,它可以显示来自tableviewcontroller中的@username或#hashtag的最新推文。没有要求发布推文或类似的东西。
目前我使用MGTwitterEngine
它很复杂,只提取与用户名相关的推文而非hastags。
我发现了tutorial,但大部分代码都没有解释,也没有源代码。
同时找到this但似乎http://search.twitter.com/search?q=%23
+ #hashtag会返回nil
个数据
还看到了这个question已编辑的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
获取主题标签?
答案 0 :(得分:4)
查看STTwitter。
STTwitterAPI *twitter =
[STTwitterAPI twitterAPIApplicationOnlyWithConsumerKey:@""
consumerSecret:@""];
[twitter verifyCredentialsWithSuccessBlock:^(NSString *bearerToken) {
[twitter getSearchTweetsWithQuery:@"Snowden"
successBlock:^(NSDictionary *searchMetadata, NSArray *statuses) {
// use the statuses here
} errorBlock:^(NSError *error) {
// ...
}];
} errorBlock:^(NSError *error) {
// ...
}];
答案 1 :(得分:0)
您可能需要在一个有效的示例源代码下面实现您自己的方法
试试这个git
https://bitbucket.org/wave_1102/hdc2010-iphone/src
在您的终端hg clone https://bitbucket.org/wave_1102/hdc2010-iphone
中输入并获取git。
在HDC2010ViewController
中使用您的#标签替换win
// search twitter for the HDC10 hashtag and add the tweets to our array
[ tweetArray addObjectsFromArray:[ tweetFactory recentTweetsForHashTag:@"win" ] ];
答案 2 :(得分:0)
您可以使用Twitter工具包在应用中显示完整的时间轴(https://docs.fabric.io/ios/twitter/show-timelines.html)。
class SearchTimelineViewController: TWTRTimelineViewController {
convenience init() {
let client = TWTRAPIClient()
let dataSource = TWTRSearchTimelineDataSource(searchQuery: "#objc", APIClient: client)
self.init(dataSource: dataSource)
// Show Tweet actions
self.showTweetActions = true
}
}