我基本上只需要一個表格視圖,它顯示來自tableviewcontroller中@username或#hashtag的最新推文。沒有要求發佈推文或類似的東西。如何在IOS中嵌入推文和/或標籤
目前我使用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
是否有任何簡單的教程或代碼示例同時獲取用戶名和hashtag推文?
或
有沒有辦法也取得與MGTwitterEngine
主題標籤?
嗨NST,如何實現這個Twitter搜索API呼叫? – Jayaprakash
使用完整方法getSearchTweetsWithQuery:其中包含sinceID和maxID參數。 – nst
非常感謝你。 +1 – Jayaprakash