[英]How to embed a Twitter feed and/or hashtag in IOS
我基本上只需要一個表視圖,該表視圖顯示tableviewcontroller中來自@username或#hashtag的最新推文。 無需發布推文或類似內容。
目前,我使用的是MGTwitterEngine
它很復雜,只能獲取與用戶名相關的推文,而不能獲取標簽。
我找到了本教程,但是沒有解釋大多數代碼,也沒有源代碼。
也找到這個,但似乎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
獲取主題標簽?
看看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) {
// ...
}];
您可能需要在有效的示例源代碼下方實現自己的方法
試試這個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" ] ];
您可以使用Twitter Kit在應用程序中顯示完整的時間軸( 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
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.