2013-01-09 39 views
2

我基本上只需要一個表格視圖,它顯示來自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主題標籤?

回答

0

您可能需要實現低於示例源代碼,工程

你自己的方法試試這個混帳

https://bitbucket.org/wave_1102/hdc2010-iphone/src

在終端hg clone https://bitbucket.org/wave_1102/hdc2010-iphone類型和取飯桶。

HDC2010ViewController你#標籤替換win

​​
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) { 
    // ... 
}]; 
+0

嗨NST,如何實現這個Twitter搜索API呼叫? – Jayaprakash

+1

使用完整方法getSearchTweetsWithQuery:其中包含sinceID和maxID參數。 – nst

+0

非常感謝你。 +1 – Jayaprakash

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 
    } 

} 

相關問題