[英]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.