Search code examples
iosfacebook-graph-apifacebook-ios-sdkapplinks

How to use Facebook Mobile Hosting API for App Links


What I want to do is very simple. I have an app that posts to Facebook and I want to create a link so that users can be redirected to my app. It is mobile only with no web hosting so I want to use Facebook's Mobile Hosting API as documented here: https://developers.facebook.com/docs/applinks/hosting-api?locale=en_GB

https://developers.facebook.com/docs/graph-api/reference/v2.2/app/app_link_hosts?locale=en_GB

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
                       @"Example App Link Host Name", @"name",
                       @"{Question 1}", @"ipad",
                       @"{\"should_fallback\": false}", @"web",
                       nil
                   ];

/* make the API call */

[FBRequestConnection startWithGraphPath:@"/{question 2}/app_link_hosts"
                         parameters:params
                         HTTPMethod:@"POST"
                  completionHandler:^(
                      FBRequestConnection *connection,
                      id result,
                      NSError *error
                  ) {
                      /* handle the result */
                  }];

Question 1: What URL/Link am I supposed to put here?

Question 2: Am I supposed to put "app" or my fbAppID here?

Question 3: If I need my App Token, how do I use that without putting it directly into my code?

Thanks for any help. I know this shouldn't be as hard and time consuming as I am making it.


Solution

  • app_link_hosts should only be called from the server-side (or done manually via curl), it should not be done from a mobile device as it requires your app secret. We will update the docs to remove the iOS and Android code blocks.

    See this doc for more info on the curl commands to use, and what the parameters mean: https://developers.facebook.com/docs/applinks/hosting-api