我正在尝试通过json加载推文,因为我正在制作推特应用。没有从json twitter获取数据的迹象。我的数组也有一个空输出。我使用API可能会出现错误吗?
-(void)twitterTimeLine{
ACAccountStore *account = [[ACAccountStore alloc]init];
ACAccountType *accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
[account requestAccessToAccountsWithType:accountType options:nil completion:^(BOOL granted, NSError *error)
{
if (granted == YES) {
NSArray *arrayOfAccounts = [account accountsWithAccountType:accountType];
if ([arrayOfAccounts count] > 0) {
ACAccountType *twitterAccount = [arrayOfAccounts lastObject];
NSURL *requestAPI = [NSURL URLWithString:@"https://api.twitter.com/1.1/statuses/home_timeline/json"];
NSMutableDictionary *parameters = [[NSMutableDictionary alloc]init];
[parameters setObject:@"100" forKey:@"count"];
[parameters setObject:@"1" forKey:@"include_entities"];
SLRequest *posts = [SLRequest requestForServiceType:SLServiceTypeTwitter requestMethod:SLRequestMethodGET URL:requestAPI parameters:parameters];
posts.account = (ACAccount *)twitterAccount;
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
[posts performRequestWithHandler:^(NSData *response, NSHTTPURLResponse *urlResponse, NSError *error){
array=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
// NSLog(@"%@",posts);
NSLog(@"%@",array);
NSLog(@"---------");
if (array.count !=0) {
dispatch_async(dispatch_get_main_queue(),^{
[timelineTableView reloadData];
});
}
}];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
else {
NSLog(@"%@", [error localizedDescription]);
}
};
}];
答案 0 :(得分:0)
试试这个:
ACAccount *twitterAccount = [arrayOfAccounts lastObject];
这可能是获得警告的原因。
使用以下网址更新您的网址: