【发布时间】:2014-05-04 06:05:08
【问题描述】:
我正在尝试使用下面的代码从给定的用户名请求和解析 20 条推文。虽然,在 NSLog 中,我得到的只是错误的身份验证错误。有人可以帮我修复我的代码并指出正确的方向吗?
提前致谢!
- (void)getTweets:(NSString *)username {
NSURL *getTimeline = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/user_timeline.json"];
NSString *paraString = [NSString stringWithFormat:@"%@", username];
NSDictionary *parameters = [NSDictionary dictionaryWithObject:paraString forKey:@"username"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:getTimeline parameters:parameters];
ACAccountStore *accountStore = [[ACAccountStore alloc] init];
ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[accountStore requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray *accounts = [accountStore accountsWithAccountType:accountType];
if (accounts.count > 0)
{
for (ACAccount *twitterAccount in accounts) {
[request setAccount:twitterAccount];
}
}
[self getTweets:@"@IsaRanjha"];
}
}
];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
if (!error)
{
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
NSLog(@"%@", json);
}
else
{
//Deal with error
}
}];}
【问题讨论】: