【问题标题】:How to invite friends to my application via facebook iOS SDK and Graph API如何通过 facebook iOS SDK 和 Graph API 邀请朋友加入我的应用程序
【发布时间】:2012-05-31 13:00:36
【问题描述】:

我正在编写一个 iPhone 应用程序。

我想让用户选择邀请朋友开始通过 Facebook 使用我的应用程序。

更具体地说,我想展示一个对话框,让用户选择要邀请的特定朋友。

我该怎么做?

谢谢。

【问题讨论】:

标签: iphone objective-c facebook facebook-graph-api facebook-ios-sdk


【解决方案1】:

很简单,只需编写以下代码即可个性化消息,还可以轻松选择要发送请求的朋友,这是一种直接且强大的方法。

 [FBWebDialogs
 presentRequestsDialogModallyWithSession:nil
 message:NSLocalizedString(@"FBinviteMessage", nil)
 title:nil
 parameters:nil
 handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {}
];

只需将这六行代码添加到您的 Button 操作方法中,其余的将由 IOS & FaceBook 内置框架完成:)

【讨论】:

  • 很好,这里的最佳答案:)
  • 由于the docs,这似乎已被弃用
  • 已弃用,最新版本的替代解决方案是什么?
【解决方案2】:

你可以这样做:

Facebook* facebook = 
   [[Facebook alloc] initWithAppId:@"YOUR_FACEBOOK_APP_ID" andDelegate:self];

NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                       @"My Title", @"title",
                                       @"Come check out my app.",  @"message",
                                       @"FACEBOOK_USER_ID", @"to",
                                       nil]; 

[facebook dialog:@"apprequests" andParams:params andDelegate:self];

您可以在此页面查看可能的参数列表(向下滚动):http://developers.facebook.com/docs/reference/dialogs/requests/

【讨论】:

  • 感谢非常有用。有没有什么办法可以在代码上知道被邀请的朋友在哪里?
  • 我的意思是,我如何在代码上知道用户为请求选择了哪些用户,以将信息保留在应用程序中
  • 嗨,我正在使用 3.1 facebook sdk。如何使用此框架自动向其他用户发送“试用应用程序”请求?
  • 现在已弃用。他们建议您改用 FBWebDialogs 类。 developers.facebook.com/docs/reference/ios/current/class/…
【解决方案3】:

今天使用 facebook SDK 的 3.11 version,您应该使用它来向特定朋友发送应用请求。

NSString *facebookID = @"YOUR_FRIEND_FACEBOOK_ID"
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObject:facebookID forKey:@"to"];

NSString *message = @"SOME_MESSAGE";
NSString *title = @"TITLE";


FBSession *facebookSession = [PFFacebookUtils session]; //You may changed this if you are not using parse.com

[FBWebDialogs presentRequestsDialogModallyWithSession:facebookSession
                                              message:message
                                                title:title
                                           parameters:params handler:
 ^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
 {

 }];

【讨论】:

    【解决方案4】:

    Facebook SDK 4.0 引入了“iOS 应用邀请”。 看看吧:https://developers.facebook.com/docs/app-invites/ios

    【讨论】:

    • 关于如何仅使用 App-Invites 邀请特定朋友的任何想法?
    • @Marcio Klepacz:我点击我在应用程序中完成的链接,它显示受邀但未收到邀请。你能帮帮我吗?我希望applink创建有问题,但找不到它。
    【解决方案5】:

    确保您的 facebook 应用程序 ID 在开发人员页面和 xcode 中的信息下相同,启用沙盒模式并且必须在开发人员页面中填写画布 url [在 facebook 类别的应用程序下]。

    NSString *facebookID = @"Your friend facebook id";;
        NSMutableDictionary* params =
        [NSMutableDictionary dictionaryWithObject:facebookID forKey:@"to"];
    
        NSString *message = @"SOME_MESSAGE";
        NSString *title = @"TITLE";
    
        [FBWebDialogs presentRequestsDialogModallyWithSession:nil
                      message:message
                    title:title
                    parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
                            if (error)
                        {
                        // Case A: Error launching the dialog or sending request.
                            NSLog(@"Error sending request.");
                        }
                        else
                        {
                            if (result == FBWebDialogResultDialogNotCompleted)
                        {
                        // Case B: User clicked the "x" icon
                            NSLog(@"User canceled request.");
                        }
                        else
                        {
                            NSLog(@"Request Sent. %@", params);
                        }
            }}];
    

    【讨论】:

      【解决方案6】:

      要发送 Facebook 应用邀请,您需要先在此处添加应用的详细信息。https://developers.facebook.com/quickstarts/?platform=app-links-host

      在 Swift 2.2、XCode 7.3 和 FBSDK 4.1 中

      1. import FBSDKShareKitimport FBSDKCoreKitimport FBSDKLoginKit

      2. 在您的 ViewController 类中添加 FBSDKAppInviteDialogDelegate

        func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [NSObject : AnyObject]!) {
            print("Initiation sent")
        
        }
        func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: NSError!) {
            print("\(error)")
        }
        
      3.     let content = FBSDKAppInviteContent();
            content.appLinkURL = NSURL(string: "fb link that you get in above developers facebook url"); //"https:// fb.me/1775107252721102" in my case
            FBSDKAppInviteDialog.showFromViewController(self, withContent: content, delegate: self);
        

      【讨论】:

        【解决方案7】:

        您可以使用共享对话框共享链接以将应用程序下载到用户的墙上,或者编写自定义 UI 元素并使用 API 调用来构建您自己的共享模块。尝试使用 Facebook iOS SDK 来简化流程,否则您将有很多工作要做。

        【讨论】:

          【解决方案8】:
          [FBWebDialogs
           presentRequestsDialogModallyWithSession:nil
           message:@"YOUR_MESSAGE_HERE"
           title:nil
           parameters:nil
           handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {
               if (error) {
                   // Error launching the dialog or sending the request.
                   NSLog(@"Error sending request.");
               } else {
                   if (result == FBWebDialogResultDialogNotCompleted) {
                       // User clicked the "x" icon
                       NSLog(@"User canceled request.");
                   } else {
                       // Handle the send request callback
                       NSDictionary *urlParams = [self parseURLParams:[resultURL query]];
                       if (![urlParams valueForKey:@"request"]) {
                           // User clicked the Cancel button
                           NSLog(@"User canceled request.");
                       } else {
                           // User clicked the Send button
                           NSString *requestID = [urlParams valueForKey:@"request"];
                           NSLog(@"Request ID: %@", requestID);
                       }
                   }
               }
          }];
          

          【讨论】:

            猜你喜欢
            • 2014-06-26
            • 2013-02-26
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多