【问题标题】:How to get the list of Facebook friends who have not installed the app?如何获取未安装应用的Facebook好友列表?
【发布时间】:2014-06-30 05:02:23
【问题描述】:

我正在开发一个社交网络应用程序。我在我的 iOS 应用程序中集成了 Facebook SDK 3.14。现在,我想获取我所有 Facebook 好友的列表,这样我就可以邀请那些没有使用该应用程序的朋友并向那些已经安装了该应用程序的朋友发送好友请求。

我可以使用"/me/friends"获取已经使用我的应用的朋友列表。

[FBRequestConnection startWithGraphPath:@"/me/friends"
                             parameters:nil
                             HTTPMethod:@"GET"
                      completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                          NSLog(@"All == %@", result);
                      }];

它会提供朋友的 Facebook id(例如 id = 654330727444458)作为响应,以便我可以向他们发送朋友请求。

要获取所有未下载该应用的 Facebook 好友列表,如果我想邀请这些好友,我需要获取所有使用 "me/taggable_friends" 的好友(如果我错了请纠正我)。

[FBRequestConnection startWithGraphPath:@"/me/taggable_friends"
                             parameters:nil
                             HTTPMethod:@"GET"
                      completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                          NSlog("%@", result);
                      }];

taggable_friends 回复中,我得到朋友的 ID 为 id = "AaLYBzZzHdzCmlytqyMAjO0OLDZIOs74Urn93ikeRmmTB3vX_Xl81OYUt4XnoWG0BDLuX67umVkheVdDjzyvm0fcqMqu84GgM9JnNHc-1B63eg",这是朋友的令牌 ID,它不是唯一的。我无法使用它,必须使用朋友的 Facebook ID 来邀请他们。不幸的是,我无法在可标记的朋友回复中找到它。

【问题讨论】:

  • 是的 taggable_friends 是错误的,因为那是为了标记朋友。这就是为什么它被称为 taggable_friends。试试invitable_friends。但是你需要成为一个画布游戏并且有一个画布实现。否则我会建议共享对话框或发送/消息对话框
  • Facebook 没有更改他们的服务器,以便您只能查看正在使用您的应用程序的朋友,而不能查看未使用您的应用程序的朋友吗?
  • @Zhang 是的,他们在 APIv2 中做到了,APIv1 应该支持到 2015 年 好问题是 Kirit 是否想创建一个需要在不久的将来重写的应用程序(至少是它的 facebook 部分)。在 API v2 中有一个端点来获取用户可以邀请到应用程序的朋友列表:developers.facebook.com/docs/games/invitable-friends/v2.0,但它“适用于具有 Facebook Canvas 应用程序的游戏”
  • @Kirit Modi 你会尝试获取 facebook 好友安装的应用列表吗?

标签: ios facebook facebook-graph-api


【解决方案1】:

这只能在明年 4 月左右停止工作的 Facebook API v1 上实现。即使现在只有现有的 Facebook 应用程序允许您使用 V1,所以如果您没有足够旧的应用程序,您将无法做到这一点。在 V2 中,您只能获得也登录到同一个应用程序的朋友,但用户 ID 对应用程序是唯一的,以防止这种情况发生。我猜 Facebook 的原因是这样做可以阻止人们通过应用向他们的朋友发送垃圾邮件:/

正如@joelrb 所说,您可以为游戏创建画布应用并使用 invitable_friends,但 FB 会审核您的“游戏”,因此您不能真正作弊。

请参阅https://developers.facebook.com/docs/apps/changelog/ 了解更多信息。

TLDR;你可以做的就是贴到墙上。艰难的。对不起。

【讨论】:

    【解决方案2】:

    使用userinstalled 字段。像这样:

    NSMutableArray *notYetUsers = [NSMutableArray array];
    FBRequest *fbRequest = [FBRequest requestForGraphPath:@"me/friends?fields=installed"];
    [fbRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
        NSAssert(!error, error.localizedDescription);
        NSArray *friends = [(NSDictionary *)result objectForKey:@"data"];
        for (NSDictionary<FBGraphUser> *user in friends) {
            if ([user[@"installed"] isEqual:@(NO)])
                [notYetUsers addObject:user];
        }
    }];
    

    notYetUsers 将包含所有尚未安装应用程序的朋友。

    【讨论】:

    • 我在 4 月 30 日之后制作了 AppId。通过使用该 appId 我没有得到所有的朋友。
    【解决方案3】:
    - (void)getFBFriendsWithCompletion:(void (^)(NSError *, id))callback
    {        
        NSString *query =  @"select uid, name, is_app_user "
                           @"from user "
                           @"where uid in (select uid2 from friend where uid1=me() )";
        NSDictionary *queryParam =
        [NSDictionary dictionaryWithObjectsAndKeys:query, @"q", nil];
        // Make the API request that uses FQL
        [FBRequestConnection startWithGraphPath:@"/fql"
                                     parameters:queryParam
                                     HTTPMethod:@"GET"
                              completionHandler:^(FBRequestConnection *connection,
                                                  id result,
                                                  NSError *error) {
                                  if (callback)
                                      callback(error, result);
                              }];
    }
    
    - (void)foo
    {    
        [self getFBFriendsWithCompletion:^(NSError *error, id result) {
           if (!error)
           {
               NSMutableArray *friendsUsingApp = [NSMutableArray array];
               NSMutableArray *friendsNotUsingApp = [NSMutableArray array];
    
               for (NSDictionary *data in result[@"data"]) {
                   if ([data[@"is_app_user"] boolValue] == NO) {
                       [friendsNotUsingApp addObject:data];
                   } else {
                       [friendsUsingApp addObject:data];
                   }
               }
    
               // Do something with friendsUsingApp and friendsNotUsingApp
           }
        }];
    }
    

    【讨论】:

    • 对不起,我得到了空结果。
    • 是的,它有效,但只有使用我的应用程序的朋友列表不是所有朋友列表
    • 尝试添加新的 Facebook SDK 版本,然后得到 fql 查询的结果。
    • ql 对于 v2.1 及更高版本已弃用
    【解决方案4】:

    taggable_friends 是指可以在发布到 Facebook 的故事中标记或提及的朋友列表。你得到的结果只是一个标记令牌,只能用于标记朋友,不能用于其他目的。

    虽然这是指游戏应用,但我认为如果您使用 invitable_friends API 会更容易。但它需要一个 Facebook Canvas 应用程序实现。您可以在 Canvas 中提供通知,让用户只使用移动应用等。

    这是使用 invitable_friends API 的教程:https://developers.facebook.com/docs/games/mobile/ios-tutorial/

    还有,invitable_friends API 详细信息: https://developers.facebook.com/docs/games/invitable-friends/v2.0

    您可以尝试这样来获取 Friends 应用用户的 ID:

    NSMutableArray *appFriendUsers = [[NSMutableArray alloc] init];
    
    [[FBRequest requestForGraphPath:@"me/friends?fields=installed"]
     startWithCompletionHandler:
     ^(FBRequestConnection *connection,
      NSDictionary *result,
      NSError *error) {
    
     //if result, no errors
     if (!error && result)
     {
         //result dictionary in key "data"
         NSArray *allFriendsList = [result objectForKey:@"data"];
    
         if ([allFriendsList count] > 0)
         {
            // Loop
            for (NSDictionary *aFriendData in allFriendsList) {
               // Friend installed app?
               if ([aFriendData objectForKey:@"installed"]) {
    
                  [appFriendUsers addObject: [aFriendData objectForKey:@"id"]];
                     break;
                }
             }
          }
      }
    }];
    

    【讨论】:

    • invitable_friends 仅用于 GAME 类别
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    • 2015-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-30
    相关资源
    最近更新 更多