Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Applinks - pass custom JSON data in al_applink_data

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"
    }
}
like image 791
skornos Avatar asked Nov 01 '22 08:11

skornos


1 Answers

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.

like image 78
Manann Sseth Avatar answered Jan 04 '23 14:01

Manann Sseth