2

我基本上只需要一个表格视图,它显示来自 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

4

3 回答 3

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) {
    // ...
}];
于 2013-08-06T14:51:41.257 回答
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" ] ]; 
于 2013-01-09T17:22:06.880 回答
0

您可以使用 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
  }
 
}

于 2016-01-26T21:53:24.497 回答