我正在努力完成这项工作。我做了一个 FBRequest 来查看谁(在我的 facebook 朋友中)安装了我的应用程序。
这是我的代码
-(void)viewDidload
{
[[FBRequest requestForMe] startWithCompletionHandler:
^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *user, NSError *error) {
if (!error) {}
NSString* fql =
@"SELECT uid FROM user WHERE is_app_user=true AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())";
[FBRequestConnection startWithGraphPath:@"/fql"
parameters:@{ @"q" : fql}
HTTPMethod:@"GET"
completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(error) {
// NSLog(@"Problem");
}
FBRequest *fql = [FBRequest requestForGraphPath:@"fql"];
[fql.parameters setObject:@"SELECT uid,name,is_app_user FROM user WHERE is_app_user AND uid IN (SELECT uid2 FROM friend WHERE uid1 = me())" forKey:@"q"];
[fql startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (result) {
//NSLog(@"result:%@", result);
//ON PARSE LE RESULT
NSArray *arrayRsult = [result objectForKey:@"data"];
NSMutableArray *ins = (NSMutableArray *) [arrayRsult valueForKey:@"is_app_user"];
NSMutableArray *ids = (NSMutableArray *) [arrayRsult valueForKey:@"uid"];
NSMutableArray *names = (NSMutableArray *) [arrayRsult valueForKey:@"name"];
NSMutableArray *recentFriends = [[NSMutableArray alloc] init];
NSMutableArray *idFriends = [[NSMutableArray alloc] init];
NSMutableArray *nameFriends = [[NSMutableArray alloc] init];
// ON A LE NOMBRE D'USER
for (NSDictionary *d in ins)
{
[recentFriends addObject:d];
[recentFriends removeObjectIdenticalTo:[NSNull null]];
}
// ON A LES IDS
for (NSDictionary *e in ids)
{
[idFriends addObject:e];
}
// ON A LES NOMS
for (NSDictionary *e in names)
{
[nameFriends addObject:e];
}
NSUInteger arrayLength = [recentFriends count];
NSLog(@"ids are : %@ ",idFriends);
NSLog(@"names are %@",nameFriends );
NSLog(@"there are %i", arrayLength);
data = [NSArray arrayWithObjects:nameFriends, nil];
displayData = [[NSMutableArray alloc]initWithArray:data];
}
else {
NSLog(@"problem , bullshit");}
}];
}
];}];
data = [NSArray arrayWithObjects:nameFriends, nil];
displayData = [[NSMutableArray alloc]initWithArray:data];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"cell"];
cell.textLabel.text = [displayData objectAtIndex:indexPath.row];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [displayData count];
}
在控制台中,我有 id 、拥有该应用程序的人数和他们的姓名。现在,我想在 tableView 中显示 NameFriends MutableArray 的结果。
当我在 facebook 请求之外编写 NSLogs 时,我想显示的数据没有出现。它们似乎为空。
这是结束这部分项目的最后一步,遗憾的是我自己无法做到这一点