繁体   English   中英

如何知道用户的哪些Facebook好友安装了我的应用?

[英]How to know which Facebook friends of the user have my application installed?

是否可以执行以下操作? 我想创建一个 iOS 应用程序,它允许用户查看他们的所有 Facebook 朋友,这些朋友已经在他们的 Facebook 列表中拥有这个应用程序。 是否可以通过Facebook ConnectGraph API或其他方式实现?

是的,这是可能的。

  1. 您将需要维护自己的应用程序安装者数据库。
  2. 当用户安装该应用程序时,他们通过其中一个 API 连接到 Facebook,获取他们的用户 ID,并将其提交到您的数据库,并带有用户安装该应用程序的标志。
  3. 然后,您通过其 API 之一向 Facebook 询问该用户的朋友 ID 列表,然后询问您的数据库,这些 ID 中的任何一个是否设置了相关标志。

如果您遵循了 Facebook 教程iOS 教程

您应该可以访问AppDelegate.m文件中的“facebook”object。 “facebook”object 已经用您的特定应用程序 ID 注册了。 然后您可以使用它来查询当前用户的已经安装了该应用程序的朋友。

这是检索朋友数据的 Facebook 查询:

NSString *fql = [NSString stringWithFormat:@"Select name, uid, pic_small from user where is_app_user = 1 and uid in (select uid2 from friend where uid1 = %@) order by concat(first_name,last_name) asc", _replace_this_with_the_fb_id_of_the_current_user_ ];

是的,您可以使用 GraphAPI 使用新的 Facebook SDK 3.5 及更高版本(2013 年 6 月)来完成。 您可以稍后根据需要使用 deviceFilteredFriends 可变数组...

// The Array for the filtered friends
NSMutableArray *installedFilteredFriends = [[NSMutableArray alloc] init];

// Request the list of friends of the logged in user (me)
[[FBRequest requestForGraphPath:@"me/friends?fields=installed"]
 startWithCompletionHandler:
 ^(FBRequestConnection *connection,
   NSDictionary *result,
   NSError *error) {

     // If we get a result with no errors...
     if (!error && result)
     {
         // here is the result in a dictionary under a key "data"
         NSArray *allFriendsResultData = [result objectForKey:@"data"];

         if ([allFriendsResultData count] > 0)
         {
            // Loop through the friends
            for (NSDictionary *friendObject in allFriendsResultData) {
               // Check if installed data available
               if ([friendObject objectForKey:@"installed"]) {

                  [installedFilteredFriends addObject: [friendObject objectForKey:@"id"]];
                     break;
                }
             }
          }
      }
 }];

使用Facebook登录,然后请求该用户的好友。 您只会得到那些安装了请求应用程序的应用程序(它曾经返回所有带有“已安装”标志的朋友)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM