【问题标题】:iOS facebook integration - sending and receiving requestsiOS facebook 集成 - 发送和接收请求
【发布时间】:2013-01-10 14:24:40
【问题描述】:

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

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

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

作为授权用户,我应该关注文档 这在打开 url 方法中:

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

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

那么基本上 target_url 是什么? 应该怎么设置? 发送请求时我必须包括什么?

另外: 应用程序句柄打开 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 的代码 sn-ps:

非常感谢您抽出宝贵的时间。

【问题讨论】:

    标签: ios facebook facebook-requests


    【解决方案1】:

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

    【讨论】:

    • 我在 fb 应用程序中启用了深度链接。 :-/
    【解决方案2】:

    Facebook sdk 3.5 requests not working

    我认为这个链接会对你有所帮助,也可以在 Facebook 上配置应用程序

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多