我正在为我的应用程序使用 iOS Facebook SDK。我的应用需要访问用户的朋友照片。然而,一些用户拒绝应用程序访问他们的照片。我想做的是过滤那些不允许应用访问他们的照片的朋友。我目前的方法是让所有朋友将 uid 保存在一个数组中,然后删除那些共享 0 张照片的朋友。这种方法的问题是效率非常低且缓慢。
您知道是否有任何方法可以使用 FQL 或 Graph API 查询该特定用户的好友权限?
以下是我目前(非常慢)的方法。
- (void)retrieveFacebookFriends
{
if (FBSession.activeSession.isOpen)
{
FBRequestConnection *fbConnection = [[FBRequestConnection alloc] init];
NSMutableArray *arrayOfFriendIDS = [[NSMutableArray alloc] init];
NSMutableArray *arrayOfFriendsNames = [[NSMutableArray alloc] init];
[fbConnection addRequest:[FBRequest requestForMyFriends] completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error)
{
FBGraphObject *graphObject = (FBGraphObject *)result;
id content = [graphObject objectForKey:@"data"];
if ([content count] > 0)
{
//sort the friends by name
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"first_name" ascending:YES];
[content sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
id value;
for (value in content)
{
[arrayOfFriendIDS addObject:[value objectForKey:@"id"]];
[arrayOfFriendsNames addObject:[value objectForKey:@"name"]];
}
NSInteger size = [arrayOfFriendIDS count];
NSMutableArray *data = [[NSMutableArray alloc] initWithCapacity:size];
for (NSInteger i = 0; i < size; i++)
{
FriendRecord *record = [[FriendRecord alloc] init];
record.friendID = [arrayOfFriendIDS objectAtIndex:i];
record.name = [arrayOfFriendsNames objectAtIndex:i];
[data addObject:record];
}
self.friendRecords = [NSArray arrayWithArray:data];
dispatch_async(dispatch_get_main_queue(), ^{
[self.tableView reloadData];
});
__block NSMutableArray *tmpArray = [self.friendRecords mutableCopy];
__block int counter = 0;
for (value in content)
{
FBRequest *fql = [FBRequest requestForGraphPath:@"fql"];
[fql.parameters setObject:[NSString stringWithFormat:@"SELECT object_id FROM photo WHERE aid IN (SELECT aid FROM album WHERE owner=%@)",[value objectForKey:@"id"]]
forKey:@"q"];
[fql startWithCompletionHandler:^(FBRequestConnection *connection,
id result,
NSError *error)
{
counter++;
if (!error)
{
id permissionData = [result objectForKey:@"data"];
if ([permissionData count] == 0)
{
FriendRecord *record = [[FriendRecord alloc] init];
record.friendID = [value objectForKey:@"id"];
record.name = [value objectForKey:@"id"];
[tmpArray removeObject:record];
}
}
else
{
NSLog(@"error %@", error);
}
//check if it is the last record
if (counter == [self.friendRecords count])
{
self.friendRecords = [NSArray arrayWithArray:tmpArray];
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@"filtering is finished");
[self.tableView reloadData];
});
}
}];
}
}
}
}];
[fbConnection start];
}
else
{
//open a facebook session
}
}
好的,我使用这个非常快的 FQL 查询部分解决了问题!
select uid, name from user where uid in (select owner from album where owner in (select uid2 from friend where uid1 = me())) order by name
但是,一些与应用程序共享照片的朋友不包含在此查询的答案中!起初我以为是因为他们没有个人专辑,但后来证实不是这样,我不知道为什么。
你能帮我解决这个奇怪的问题吗?非常感谢!