5

is it possible to pass custom data in al_applink_data using Facebook applinks?

I can retrieve this JSON example but I cannot see a place where to append my custom data to it. If this is not possible than my only solution is to parse obtained URL but this doesn't seem much bulletproof.

{
    "target_url": "https://www.example.com/abc.html",
    "extras": {
        "fb_app_id": [YOUR_FACEBOOK_APP_ID],
        "fb_access_token": "[ACCESS_TOKEN']",
        "fb_expires_in": "3600"
    },
    "referer_app_link": {
        "url": "[FACEBOOK_APP_BACK_LINK]",
        "app_name": "Facebook"
    }
}
skornos
  • 3,121
  • 1
  • 26
  • 30

2 Answers2

2

Parsing Data

My solution by creating custom data for target_url.

NSDictionary *dictionary = @{ @"target_url" : @"YOUR_VALUE"};
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionary options:0 error:nil];
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];

Then, append with your Facebook app link ID with al_applink_data key in FB Graph Object dictionary.

[NSString stringWithFormat:@"https://fb.me/FB_LINK_ID?al_applink_data=%@", jsonString]

That's it.!!

Retrieving Callback URL

if([[call appLinkData] targetURL] != nil)
{
    NSURL *targetUrl = [[call appLinkData] targetURL];

    //Actual URL
    NSString *urlString = [[targetUrl absoluteString] stringByRemovingPercentEncoding];

    URLParser *parser = [[URLParser alloc] initWithURLString:urlString];

    //Fetching value for 'al_applink_data'
    NSString *appLinkData = [parser valueForVariable:@"al_applink_data"];

    NSData *objectData = [appLinkData dataUsingEncoding:NSUTF8StringEncoding];

    //Dictionary with 'target_key' key and its value.
    NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:nil];
    NSLog(@"%@", json);
}

Reference for URL parsing : URLParser

Thanks.

Community
  • 1
  • 1
Manann Sseth
  • 2,745
  • 2
  • 30
  • 50
  • On a pedantic note, if you're appending query parameters to the fb.me url, you should probably use anything BUT al_applink_data as a key. al_applink_data should be reserved for the protocol. You're free to use any arbitrary key/value for the query parameter, so you should use something that makes sense for your application, and not al_applink_data. – Ming Li Mar 31 '15 at 22:45
0

The "extras" map was designed to carry arbitrary metadata. What type of custom data do you need? Passing of custom data through the "extras" blob requires the caller to know something about your app (so they can actually add the data).

Ming Li
  • 15,672
  • 3
  • 37
  • 35