简体   繁体   English

如何获取尚未安装该应用程序的Facebook好友列表?

[英]How to get the list of Facebook friends who have not installed the app?

I'm developing a social networking app. 我正在开发一个社交网络应用程序。 I've integrated Facebook SDK 3.14 in my iOS App. 我在我的iOS应用程序中集成了Facebook SDK 3.14。 Now, I want to get the list of all my Facebook friends so I can invite those friends who are not using the app and send friend requests to those friends who have already installed the app. 现在,我想获取所有Facebook好友的列表,这样我就可以邀请那些没有使用该应用程序的朋友,并向已安装该应用程序的朋友发送好友请求。

I can get the list of friends who already use my apps using "/me/friends" . 我可以使用"/me/friends"获取已经使用我的应用程序的朋友列表。

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

It gives friends' Facebook ids (ex. id = 654330727444458) in response so that I can send friend requests to them. 它给朋友的Facebook ID(例如id = 654330727444458)作为回应,以便我可以向他们发送朋友请求。

To get the list of all Facebook friends who have not downloaded the app and if I want to invite those, I need to get all friends using "me/taggable_friends" (Please correct me if I'm wrong). 要获取所有未下载应用程序的Facebook好友的列表,如果我想邀请那些,我需要使用"me/taggable_friends"让所有朋友(如果我错了请纠正我)。

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

In the taggable_friends response I'm getting friend's id as id = "AaLYBzZzHdzCmlytqyMAjO0OLDZIOs74Urn93ikeRmmTB3vX_Xl81OYUt4XnoWG0BDLuX67umVkheVdDjzyvm0fcqMqu84GgM9JnNHc-1B63eg " which is friend's token id and it's not unique. taggable_friends响应中我得到朋友的id为id = "AaLYBzZzHdzCmlytqyMAjO0OLDZIOs74Urn93ikeRmmTB3vX_Xl81OYUt4XnoWG0BDLuX67umVkheVdDjzyvm0fcqMqu84GgM9JnNHc-1B63eg ”这是朋友的令牌ID并且它不是唯一的。 I couldn't use it instead, have to use Facebook Id of friend to invite them. 我无法使用它,必须使用朋友的Facebook Id邀请他们。 Unfortunately, I couldn't get it in the taggable friend response. 不幸的是,我无法在可标记的朋友回复中得到它。

This is only possible on the Facebook API v1 which stops working next April or so. 这只能在Facebook API v1上实现,该API将于明年4月左右停止工作。 Even now only existing Facebook apps will allow you to use V1 so if you don't have an old enough app you are not able to do this. 即使现在只有现有的Facebook应用程序允许您使用V1,所以如果您没有足够旧的应用程序,则无法执行此操作。 In V2 you can only get friends who have also signed in to the same app but the user id's are unique to the application to prevent exactly this. 在V2中,您只能获得已登录同一应用程序的朋友,但用户ID对于应用程序是唯一的,以防止这种情况发生。 I guess Facebook reasons that by doing this is stops people spamming their friends via apps so much :/ 我猜Facebook的原因是,通过这样做可以阻止人们通过应用程序向朋友发送垃圾邮件:

As @joelrb says you can create a canvas app for a game and use invitable_friends but FB will vet your "game" so you can't really cheat. 正如@joelrb所说,你可以为游戏创建一个画布应用程序并使用invitable_friends但FB会审核你的“游戏”,所以你不能真正作弊。

See https://developers.facebook.com/docs/apps/changelog/ for more info. 有关详细信息,请参阅https://developers.facebook.com/docs/apps/changelog/

TLDR; TLDR; post to wall is all you can do. 你可以做到贴墙。 Tough. 强硬。 Sorry. 抱歉。

Use the installed field of a user . 使用userinstalled字段。 Like so: 像这样:

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 would contain all friends who have not installed the app yet. notYetUsers将包含尚未安装该应用程序的所有朋友。

- (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
       }
    }];
}

taggable_friends refers to a list of friends that can be tagged or mentioned in stories published to Facebook. taggable_friends是指可以在发布到Facebook的故事中标记或提及的朋友列表。 The result you got is just a tagging token which can only be used in order to tag a friend, and for no other purpose. 您获得的结果只是一个标记令牌,只能用于标记朋友,而不能用于其他目的。

Although this refers to a game app, it's easier I think if you use the invitable_friends API. 虽然这是指游戏应用程序,但如果您使用invitable_friends API,我认为更容易。 But it requires a Facebook Canvas app implementation. 但它需要Facebook Canvas应用程序实现。 You may just provide a notice in your Canvas for users to just use the mobile app instead, etc. 您可以在Canvas中提供通知,以便用户只需使用移动应用程序等。

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

And, the invitable_friends API details: https://developers.facebook.com/docs/games/invitable-friends/v2.0 而且, invitable_friends API详细信息: https//developers.facebook.com/docs/games/invitable-friends/v2.0

You can try this to get the IDs of Friends app users: 您可以尝试此操作来获取好友应用用户的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;
            }
         }
      }
  }
}];

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

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