Note that there are some explanatory texts on larger screens.

plurals
  1. POiOS facebook integration - sending and receiving requests
    text
    copied!<p>I use a facebook api to connect to facebook and send request via native dialogs provided by the api.</p> <p>I followed the sample posted in the docs on developers.facebook.com But I have following problem sending requests : 1. The requests are not shown in notifications - only in application center - In this case i think that it is a problem of that the app is in sandbox and not posted to APPSTORE</p> <ol> <li>I succesfully send request to facebook server with right fbUser id. But when I want to receive the notification in app here comes the problem : </li> </ol> <p>Following the docs as an authorized user I should se this in open url method:</p> <pre><code>fb[APP_ID]://authorize#expires_in=[ACCESS_TOKEN_EXPIRATION] &amp;access_token=[USER_ACCESS_TOKEN] &amp;target_url=https://apps.facebook.com/[APP_NAME_SPACE]/?request_ids= [COMMA_SEPARATED_REQUESTIDs]&amp;ref=notif&amp;app_request_type=user_to_user </code></pre> <p>But i can see only plain login without targer url .... I can see session expiration date, fb app id, access token and so on. But no target url?</p> <p>So basically what the target_url is? How it should be set? What i have to include when sending request? </p> <p>In addition : application handle open url method is called properly. checkRequests method is also called properly after app becomes active.</p> <p>Please do not link me to the docs. I have read it moreless 50 times and didn't find any reasonable solution... </p> <pre><code>- (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; } } </code></pre> <p>Is there any way that these problems are caused by the way that the app is not published on Appstore (Appstore id is not set neither for iPhone nor iPad)?</p> <p>Here are code snippets showing using of the fb api:</p> <p>Thank you very much for the time. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload