Virender Virender - 1 year ago 138
Android Question

Facebook fitness open graph story with map and route on Map

I am trying to create fitness run story. I am able to post the story with info of distance, duration, calories etc but not able to show map as endomondo, nike running, runkeeper apps are doing.

enter image description here

Nike+ running app show fitness run info

enter image description here

My App show run info :(

I also tried to create custom open graph story with new action and objects but that also not work for me. Does anyone have some idea how to do this in iOS or PHP side?

Answer Source

This is the code for create fitness run story with map & polyline on facebook.

    NSMutableDictionary *dictonary = [[NSMutableDictionary alloc] init];
    [dictonary setObject:@"fitness.course" forKey:@"og:type"];
    [dictonary setObject:@"Name which you want to share" forKey:@"og:title"];
    [dictonary setObject:@"A url which will be open on click" forKey:@"og:url"];
    [dictonary setObject:@"set description like you ran 5km in 40 min" forKey:@"og:description"];
    //duration of the activity
    [dictonary setObject:@"2400" forKey:@"fitness:duration:value"];
    //time unit, s stands for seconds
    [dictonary setObject:@"s" forKey:@"fitness:duration:units"];
    //distance of the activity
    [dictonary setObject:@"5" forKey:@"fitness:distance:value"];
    //distance unit in KM
    [dictonary setObject:@"km" forKey:@"fitness:distance:units"];
    //speed distance in meter / time in seconds
    [dictonary setObject:@(distance/speed) forKey:@"fitness:speed:value"];
    [dictonary setObject:@"m/s" forKey:@"fitness:speed:units"];
    //here adding lat lngs in the request for show map on facebook activity
    int i=0;
    for (NSDictionary *location in locationArray) {
        CLLocation *loc=[[CLLocation alloc] initWithDictionary:location];
        [dictonary setObject:[NSNumber numberWithDouble:loc.coordinate.latitude] forKey:[NSString stringWithFormat:@"fitness:metrics[%d]:location:latitude",i]];
        [dictonary setObject:[NSNumber numberWithDouble:loc.coordinate.longitude] forKey:[NSString stringWithFormat:@"fitness:metrics[%d]:location:longitude",i]];
    FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:dictonary];
    FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
    action.actionType = @"fitness.runs";
    [action setObject:object forKey:@"fitness:course"];
    FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
    content.action = action;
    content.previewPropertyName = @"fitness:course";

    [FBSDKShareDialog showFromViewController:self withContent:content delegate:self];