[英]Facebook iOS SDK - Sending a facebook user an app request
我試圖通過Facebook使用facebook iOS SDK發送應用程序請求,我使用以下代碼:
NSString *message = [[NSString alloc] initWithFormat:@"blah blah blah"];
NSString *data = [[NSString alloc] initWithFormat:@"blah blah blah"];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:message, @"message", data, @"data", nil];
[_facebook requestWithGraphPath:[NSString stringWithFormat:@"%@/apprequests",userID] andParams:params andHttpMethod:@"POST" andDelegate:self];
[message release];
[data release];
這給了我以下錯誤:
Error: Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x788c5b0 {error=<CFBasicHash 0x788c080 [0x1bf53e0]>{type = mutable dict, count = 2,
entries =>
2 : <CFString 0x788b560 [0x1bf53e0]>{contents = "type"} = <CFString 0x788c3f0 [0x1bf53e0]>{contents = "OAuthException"}
3 : <CFString 0x788c560 [0x1bf53e0]>{contents = "message"} = <CFString 0x788c480 [0x1bf53e0]>{contents = "(#200) Invalid Request: There was a problem with the parameters of the request. Body of an error/warning message. Title is: Invalid Request"}
}
那么有沒有人成功用這個,或者你知道一種使用facebook iOS SDK向facebook用戶發送請求的方法嗎?
謝謝
您可以使用Facebook SDK輕松發送應用程序請求
如需制作應用程序請求請確保執行以下步驟
1)確保在應用程序文件夾中添加了最新的Facebook SDK
如果沒有,你可以從下載該鏈接。
現在,您只需在項目文件夾中添加FBConnect文件夾即可。
2)然后確保您已將您的iphone應用程序注冊為“Facebook上的應用程序”類型在“基本應用程序設置”下選擇您的應用程序如何與Facebook集成。
如果沒有,你可以在這里做。
NSString *friendId=@"FacebookId Of Your Friends";
NSLog(@"%@",friendId);
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Hi please add me as a friend.", @"message",
friendId, @"to",
nil];
[appDelegate.facebook dialog:@"apprequests" andParams:params andDelegate:self];
請不要忘記在ViewController類中首先采用FBdialogDelegate協議。
僅使用POST方法,無法在沒有對話框的情況下發送應用程序請求。
根據文件 :
此SDK提供了彈出Facebook對話框的方法。 當前支持的對話框是授權流程中使用的登錄和權限對話框,以及用於將帖子發布到用戶的源的對話框。
因此,您也無法通過標准對話框發布應用請求。 它僅適用於Web應用程序。
andyc,使用這種方式你只能發送App請求。 請確保您已將App注冊為“App On Facbook”。 問題是,為了在桌面網站上顯示通知,您的Facebook App需要定義Canvas URL。 URL甚至不需要有效,只需要在應用程序的設置中定義。 我已經通過測試應用驗證了這確實解決了問題。 這是由Facebook有意完成的,因為當用戶點擊通知時,它們會被發送到桌面網站上的Canvas URL
我以同樣的方式做了事情,我在通知中收到了App請求。 仍然有發送應用程序請求的問題,請查看以下鏈接
試試這段代碼,
NSDictionary *params = @{@"to":text};
NSString *message = @"MESSAGE";
NSString *title = @"TITLE";
[FBWebDialogs presentRequestsDialogModallyWithSession:nil
message:message
title:title
parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
if (error)
{
UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Request not sent" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[Alert show];
}
else
{
if (result == FBWebDialogResultDialogNotCompleted)
{
// Case B: User clicked the "x" icon
UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Canceled request" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[Alert show];
NSLog(@"User canceled request.");
}
else
{
UIAlertView *Alert = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Request sent successfully" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[Alert show];
NSLog(@"Request Sent. %@", params);
}
}
}];
我能夠通過標准POST向/ me / apprequests使用Ruby發送請求。 我為應用程序提供了有效的access_token和“message”參數。 有可能,iOS SDK還沒有對話框。
注意:用戶必須先安裝應用程序,然后才能向他們發送通知和邀請。 所以安德魯是對的。 目前還無法發送應用請求邀請某人加入新應用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.