gpt4 book ai didi

ios - 通过应用发送 facebook 请求

转载 作者:行者123 更新时间:2023-12-01 16:42:22 25 4
gpt4 key购买 nike

我阅读了 facebook 文档并实现了我的代码,但是请求没有发送。我在网站上看不到请求通知。我可以在我的日志屏幕上看到请求 ID。

这是我的部分代码:
我从 developer.facebook.com 获取了这段代码

+ (NSDictionary*)parseURLParams:(NSString *)query {
NSArray *pairs = [query componentsSeparatedByString:@"&"];
NSMutableDictionary *params = [[NSMutableDictionary alloc] init];
for (NSString *pair in pairs) {
NSArray *kv = [pair componentsSeparatedByString:@"="];
NSString *val =
[kv[1] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
params[kv[0]] = val;
}
return params;
}

+(void) requestFriendMethod{

// Display the requests dialog
[FBWebDialogs
presentRequestsDialogModallyWithSession:nil
message:@"message"
title:@"title"
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 = [AKFacebook 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);
}
}
}
}];

}

我究竟做错了什么?感谢您的回答和建议。

最佳答案

确保您的 Facebook 应用程序 ID 在开发人员页面和 xcode 中的信息下相同,启用沙盒模式并且必须在开发人员页面中填写 Canvas 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);
}
}}];

关于ios - 通过应用发送 facebook 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23131910/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com