[英]How to invite friends to my application via facebook iOS SDK and Graph API
我正在写一个iPhone应用程序。
我想让用户选择邀请朋友开始通过Facebook使用我的应用程序。
更具体地说,我想提供一个对话框,让用户选择要邀请的特定朋友。
我怎样才能做到这一点?
谢谢。
很简单,您只需编写下面的个性化消息代码,您也可以轻松选择要向其发送请求的朋友,这是一种直接而强大的方法。
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:NSLocalizedString(@"FBinviteMessage", nil)
title:nil
parameters:nil
handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error) {}
];
只需将这六行代码添加到Button动作方法中,其余部分将由IOS和FaceBook Inbuilt框架完成:)
你可以这样做:
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.11 version
的facebook SDK,你应该使用它来向特定的朋友发送应用请求。
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)
{
}];
Facebook SDK 4.0推出了“App Appites for iOS”。 请查看: https : //developers.facebook.com/docs/app-invites/ios
确保您的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);
}
}}];
要发送Facebook应用邀请,您需要先在此处添加您的应用的详细信息.. https://developers.facebook.com/quickstarts/?platform=app-links-host
在Swift 2.2中,XCode 7.3和FBSDK 4.1
import FBSDKShareKit
import FBSDKCoreKit
import FBSDKLoginKit
使用ViewController类添加FBSDKAppInviteDialogDelegate
。
func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didCompleteWithResults results: [NSObject : AnyObject]!) { print("Initiation sent") } func appInviteDialog(appInviteDialog: FBSDKAppInviteDialog!, didFailWithError error: NSError!) { print("\\(error)") }
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);
您可以使用共享对话框共享链接以将应用程序下载到用户的墙上,也可以编写自定义UI元素并使用API调用来构建您自己的共享模块。 尝试使用Facebook iOS SDK来简化流程,否则您将需要做很多工作。
[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);
}
}
}
}];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.