3

Has anyone realized a share for a fitness course with Facebook SDK 4.2.0? I have a track of CLLocation objects in an array and would like to share this as a course in Facebook. Duration and distance is shown, but no track on the map. That means, my problem is to realize the fitness:metric:location section. Any help?

Here is my source code, very simple. All I want is adding some more locations to show the track. But NSDictionary is not allowing multiple entries for the same key, so adding it to properties is not possible.

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

NSDictionary *properties = @{
                             @"og:type": @"fitness.course",
                             @"og:title": @"YapYap Track",
                             @"og:description": @" ",
                             @"fitness:duration:value": appDelegate.actEvent.nDurationInSeconds,
                             @"fitness:duration:units": @"s",
                             @"fitness:distance:value": [NSNumber numberWithDouble:appDelegate.actEvent.nTracklengthInMeter.doubleValue/1000.0],
                             @"fitness:distance:units": @"km",
                             @"fitness:speed:value": [NSNumber numberWithDouble:appDelegate.actEvent.nTracklengthInMeter.doubleValue/appDelegate.actEvent.nDurationInSeconds.doubleValue],
                             @"fitness:speed:units": @"m/s",

                             @"fitness:metrics:location:latitude": appDelegate.actEvent.lat,
                             @"fitness:metrics:location:longitude": appDelegate.actEvent.lon,
                             };
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
FBSDKShareOpenGraphAction *action = [[FBSDKShareOpenGraphAction alloc] init];
action.actionType = @"fitness.walks";
[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];
2
  • Does it work when you use NSMutableDictionary instead of NSDictionary? NSMutableDictionary should allow non-unique keys; it's not clear how FBSDKShareOpenGraphObject will handle taking a subclass instead of NSDictionary but it may be OK
    – Igy
    Commented Jun 5, 2015 at 22:32
  • Thanks, Igy. But same with NSMutableDictionary, this is also overriding the fitness:metrics:location entries. Commented Jun 6, 2015 at 16:09

1 Answer 1

3

I encounter this issue and manage to solve it. To do that I mixed 2 articles : - the location model you used https://developers.facebook.com/docs/opengraph/guides/fitness - the way you enter many points (last paragraph about open graph complex objects) : https://developers.facebook.com/docs/sharing/opengraph/ios

So I defined an index [i] after the word metrics and it worked !

Here is my code (in swift, but it should be the same in objective C) :

var properties: [String : AnyObject] = [
        "og:type": "fitness.course",
        "og:title": "Run",
        "og:description": "Run",
        "fitness:duration:value": run.duration,
        "fitness:duration:units": "s",
        "fitness:distance:value": run.distance,
        "fitness:distance:units": "m",
        "fitness:speed:value": run.speed,
        "fitness:speed:units": "m/s"
    ];

    var i = 0;

    for point in run.path {
        properties["fitness:metrics[\(i)]:location:latitude"] = point.latitude
        properties["fitness:metrics[\(i)]:location:longitude"] = point.longitude
        properties["fitness:metrics[\(i)]:location:altitude"] = point.altitude
        properties["fitness:metrics[\(i)]:timestamp"] = SRUtils.formatDate( NSDate(timeIntervalSinceReferenceDate: point.timestamp), format: "yyyy'-'MM'-'dd'T'HH':'mm'")
        i++;


    }

    let object = FBSDKShareOpenGraphObject(properties: properties);
1
  • I LOVE YOU!!! :) Thanks! the [\(i)] did the trick to add the locations as array!!! THANK YOU!!!!
    – Georg
    Commented Jan 25, 2016 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.