gpt4 book ai didi

iOS facebook 集成 - 发送和接收请求

转载 作者:行者123 更新时间:2023-11-29 04:12:03 25 4
gpt4 key购买 nike

我使用 facebook api 连接到 facebook 并通过 api 提供的 native 对话框发送请求。

我按照developers.facebook.com上的文档中发布的示例进行操作但我在发送请求时遇到以下问题: 1.请求未显示在通知中 - 仅在应用程序中心中 - 在这种情况下,我认为问题在于应用程序位于沙箱中并且未发布到应用程序商店

  1. 我成功使用正确的 fbUser ID 向 facebook 服务器发送请求。但是当我想在应用程序中接收通知时,问题就来了:

作为授权用户,我应该遵循文档这在打开网址方法中:

fb[APP_ID]://authorize#expires_in=[ACCESS_TOKEN_EXPIRATION]
&access_token=[USER_ACCESS_TOKEN]
&target_url=https://apps.facebook.com/[APP_NAME_SPACE]/?request_ids=
[COMMA_SEPARATED_REQUESTIDs]&ref=notif&app_request_type=user_to_user

但我只能看到没有目标网址的普通登录...我可以看到 session 到期日期、fb 应用程序 ID、访问 token 等。但没有目标网址?

那么 target_url 基本上是什么?应该如何设置呢?发送请求时我必须包含什么?

此外:应用程序句柄 open url 方法被正确调用。应用程序激活后也会正确调用 checkRequests 方法。

请不要将我链接到文档。我读了不到50遍,没有找到任何合理的解决方案......

- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
self.openedURL = url;
NSLog(@"%@",url);
return [FBSession.activeSession handleOpenURL:url];
}


- (void)sendRequest {
FBSBJSON *jsonWriter = [FBSBJSON new];
NSDictionary *gift = [NSDictionary dictionaryWithObjectsAndKeys:
@"5", @"points",
@"1", @"badge",
nil];

NSString *giftStr = [jsonWriter stringWithObject:gift];
NSMutableDictionary* params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
@"Hi from test app", @"message",
giftStr, @"data",
nil];

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

// Handle the request call back
- (void)dialogCompleteWithUrl:(NSURL *)url {
NSDictionary *params = [self parseURLParams:[url query]];
NSString *requestID = [params valueForKey:@"request"];
NSLog(@"Request ID: %@", requestID);
}
-(FBSession*)returnSession{
return self.session;
}
/*
* Helper function to get the request data
*/
- (void) notificationGet:(NSString *)requestid {
[FBRequestConnection startWithGraphPath:requestid
completionHandler:^(FBRequestConnection *connection,
id result,
NSError *error) {
if (!error) {
NSString *title;
NSString *message;
if ([result objectForKey:@"data"]) {
title = [NSString
stringWithFormat:@"%@ sent you a gift",
[[result objectForKey:@"from"]
objectForKey:@"name"]];
FBSBJSON *jsonParser = [FBSBJSON new];
NSDictionary *requestData =
[jsonParser
objectWithString:[result objectForKey:@"data"]];
message =
[NSString stringWithFormat:@"Badge: %@, Karma: %@",
[requestData objectForKey:@"badge"],
[requestData objectForKey:@"points"]];
} else {
title = [NSString
stringWithFormat:@"%@ sent you a request",
[[result objectForKey:@"from"] objectForKey:@"name"]];
message = [NSString stringWithString:
[result objectForKey:@"message"]];
}
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil,
nil];
[alert show];
// Delete the request notification
[self notificationClear:[result objectForKey:@"id"]];
}
}];
}

/*
* Helper function to check incoming URL
*/
- (void) checkIncomingNotification {

if (self.openedURL) {
NSString *query = [self.openedURL fragment];
if (!query) {
query = [self.openedURL query];
}
NSDictionary *params = [self parseURLParams:query];
for (NSString * str in [params allKeys]) {

NSLog(@"key %@", str);
}
// Check target URL exists
NSString *targetURLString = [params valueForKey:@"target_url"];

if (targetURLString) {
NSURL *targetURL = [NSURL URLWithString:targetURLString];
NSDictionary *targetParams = [self parseURLParams:[targetURL query]];
NSString *ref = [targetParams valueForKey:@"ref"];
// Check for the ref parameter to check if this is one of
// our incoming news feed link, otherwise it can be an
// an attribution link
if ([ref isEqualToString:@"notif"]) {
// Get the request id
NSString *requestIDParam = [targetParams
objectForKey:@"request_ids"];
NSArray *requestIDs = [requestIDParam
componentsSeparatedByString:@","];

// Get the request data from a Graph API call to the
// request id endpoint
[self notificationGet:[requestIDs objectAtIndex:0]];
}
}
// Clean out to avoid duplicate calls
self.openedURL = nil;
}
}

这些问题是否有可能是由于应用程序未在Appstore上发布(iPhone和iPad均未设置Appstore id)导致的?

以下是显示使用 fb api 的代码片段:

非常感谢您抽出时间。

最佳答案

在 Facebook 应用设置中启用深层链接

关于iOS facebook 集成 - 发送和接收请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14260072/

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