【问题标题】:Retrieve facebook friends & invite them to my iOS app检索 Facebook 好友并邀请他们加入我的 iOS 应用
【发布时间】:2012-12-06 05:09:30
【问题描述】:

我正在开发一个 iOS 应用程序,我想在其中检索我的 facebook 朋友并将其发送到服务器,以检查谁已经使用他们的电子邮件或电话号码使用此应用程序。一旦我得到不使用我的应用程序的朋友,我将显示“邀请”按钮向他们的电子邮件地址发送一封电子邮件,其中包含应用商店链接以下载该应用程序。

但根据 facebook 权限,我们无法检索 facebook 好友的电子邮件地址。 谁能知道我如何以其他方式实现此功能? 任何形式的帮助表示赞赏。谢谢。

【问题讨论】:

    标签: objective-c ios5 facebook-ios-sdk email-address


    【解决方案1】:

    您无法检索 Facebook 朋友的电子邮件地址,但您可以在他们的墙上发布您想要发布的任何链接,即应用商店链接以下载该应用。

    【讨论】:

    • 感谢您的回复...但我不想在每个朋友的墙上发帖。我只想将链接发布给不使用我的应用的朋友。
    • 您可以按已注册和未注册对您的朋友进行分类,然后只在未注册的朋友墙上发帖
    • 我如何分类我的朋友?凭什么我无法检索他们的电子邮件地址或电话号码?
    • 当您登录任何应用程序时,会为每个唯一的 fbid 生成 FbaccessToken。如果您的任何朋友登录了您的应用程序,他将获得一个 fbaccesstoken。您可以将该 fbid 和 fbaccesstoken 保存到您的服务器,并在此基础上检查谁已注册,谁未注册
    • 如果用户从他们的 Facebook 设置中撤消了应用程序怎么办?
    【解决方案2】:

    你可以看看我的this 线程。

    由于 facebook 不提供电子邮件地址,因此此解决方案背后的想法是,您可以在 AppStore 中发送带有指向您的应用程序链接的邀请好友请求。为了完成这个案例,我已经简要描述了链接中要遵循的步骤。

    邀请信息可能如下所示:

    我想让你试试 XYZ 游戏。这是此链接 应用商店申请: Facebook iOS SDK - get friends list

    【讨论】:

      【解决方案3】:

      您可以使用下面的 FB Graph API(/me/invitable_friends) 来获取非应用好友 -

      // m_invitableFriends - 保存邀请好友列表的全局数组

      - (void) getAllInvitableFriends
      {
          NSMutableArray *tempFriendsList =  [[NSMutableArray alloc] init];
          NSDictionary *limitParam = [NSDictionary dictionaryWithObjectsAndKeys:@"100", @"limit", nil];
          [self getAllInvitableFriendsFromFB:limitParam addInList:tempFriendsList];
      }
      
      - (void) getAllInvitableFriendsFromFB:(NSDictionary*)parameters
                                  addInList:(NSMutableArray *)tempFriendsList
      {
          [FBRequestConnection startWithGraphPath:@"/me/invitable_friends"
                                       parameters:parameters
                                       HTTPMethod:@"GET"
                                completionHandler:^(
                                                    FBRequestConnection *connection,
                                                    id result,
                                                    NSError *error
                                                    ) {
                                    NSLog(@"error=%@",error);
      
                                    NSLog(@"result=%@",result);
      
                                    NSArray *friendArray = [result objectForKey:@"data"];
      
                                    [tempFriendsList addObjectsFromArray:friendArray];
      
                                    NSDictionary *paging = [result objectForKey:@"paging"];
                                    NSString *next = nil;
                                    next = [paging objectForKey:@"next"];
                                    if(next != nil)
                                    {
                                        NSDictionary *cursor = [paging objectForKey:@"cursors"];
                                        NSString *after = [cursor objectForKey:@"after"];
                                        //NSString *before = [cursor objectForKey:@"before"];
                                        NSDictionary *limitParam = [NSDictionary dictionaryWithObjectsAndKeys:
                                                                    @"100", @"limit", after, @"after"
                                                                    , nil
                                                                    ];
                                        [self getAllInvitableFriendsFromFB:limitParam addInList:tempFriendsList];
                                    }
                                    else
                                    {
                                        [self replaceGlobalListWithRecentData:tempFriendsList];
                                    }
                                }];
      }
      
      - (void) replaceGlobalListWithRecentData:(NSMutableArray *)tempFriendsList
      {
          // replace global from received list
          [m_invitableFriends removeAllObjects];
          [m_invitableFriends addObjectsFromArray:tempFriendsList];
          //NSLog(@"friendsList = %d", [m_invitableFriends count]);
          [tempFriendsList release];
      }
      

      用于邀请非应用好友 -

      您将获得带有我/invitable_friends graph api返回的朋友列表的邀请令牌。您可以将这些邀请令牌与 FBWebDialogs 一起使用,如下所示向朋友发送邀请

      - (void) openFacebookFeedDialogForFriend:(NSString *)userInviteTokens {
      
          NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                         userInviteTokens, @"to",
                                         nil, @"object_id",
                                         @"send", @"action_type",
                                         actionLinksStr, @"actions",
                                         nil];
      
          [FBWebDialogs
           presentRequestsDialogModallyWithSession:nil
           message:@"Hi friend, I am playing game. Come and play this awesome game with me."
           title:nil
           parameters:params
           handler:^(
                     FBWebDialogResult result,
                     NSURL *url,
                     NSError *error)
           {
               if (error) {
                   // Error launching the dialog or sending the request.
                   NSLog(@"Error sending request : %@", error.description);
               }
               else
               {
                   if (result == FBWebDialogResultDialogNotCompleted)
                   {
                       // User clicked the "x" icon
                       NSLog(@"User canceled request.");
                       NSLog(@"Friend post dialog not complete, error: %@", error.description);
                   }
                   else
                   {
                       NSDictionary *resultParams = [g_mainApp->m_appDelegate parseURLParams:[url query]];
      
                       if (![resultParams valueForKey:@"request"])
                       {
                           // User clicked the Cancel button
                           NSLog(@"User canceled request.");
                       }
                       else
                       {
                           NSString *requestID = [resultParams valueForKey:@"request"];
      
                           // here you will get the fb id of the friend you invited,
                           // you can use this id to reward the sender when receiver accepts the request
      
                           NSLog(@"Feed post ID: %@", requestID);
                           NSLog(@"Friend post dialog complete: %@", url);
                       }
                   }
               }
           }];
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多