Ben Dorman
Ben Dorman

Reputation: 123

Facebook open graph - Get friends "User-owned objects"

I am currently in the progress of writing an IOS app using the FB SDK 3.5.

I have created an app that can create an "user owned object" using the following code:

    NSMutableDictionary<FBOpenGraphObject> *object = [FBGraphObject openGraphObjectForPost];
    object.provisionedForPost = YES;        
    object[@"type"] = @"fbltest:Highscore";
    object[@"title"] = @"New high score";
    object[@"privacy"] = @"EVERYONE";
    object[@"data"][@"leaderboard"] = @"0";
    object[@"data"][@"score"] = @"266";

    [FBRequestConnection startForPostOpenGraphObject:object
                                   completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
     {
        // DO STUFF HERE
     }];

I tested the object in the Object debugger and all seems to be in order. I can also retrieve a list of user objects using the following code:

    FBRequestConnection* connection = [[FBRequestConnection alloc] init];
        FBRequest* request = [[FBRequest alloc] initWithSession:FBSession.activeSession graphPath:@"me/objects/fbltest:highscore"];

        [connection addRequest:request
             completionHandler:^(FBRequestConnection *connection, id result, NSError *error)
            {
                // DO STUFF HERE
             }];
    [connection start];

Now what I would like to do is retrieve a list of the users friends Objects, initially I gained a list of friends and then would use the following path to retrieve a list of there objects: "/objects/fbltest:highscore". This returned nothing.

I then tried querying Facebook open graph with the following open graph paths to no success: "me/friends/fbltest:highscore "me/friends/objects/fbltest:highscore" "me/friends?limit=10&objects/fbltest:highscore"

Some notes: For the test environment I am using 3 test users who are all friends with each other. I have disabled the "Sandbox environment" parameter for the facebook APP.

Any help would be much appreciated, even if it just a confirmation that it is possible to read friends self hosted objects.

Upvotes: 3

Views: 1026

Answers (1)

Vincent VM
Vincent VM

Reputation: 86

I've been trying to do the same thing (querying friends' user-owned objects) but have only managed it an indirect way. I would have expected /<userid>/objects/myapp:score to work as well, but I just got no data back.

What does work, though, is querying your friends' custom actions, rather than objects. E.g.: /<userid>/myapp:actiontype.

From the actions, you can get the associated objects; ids, which you can then simply query as /<objectid>.

This does seem like a roundabout way of doing things, as it means you'll need to create an associated action for every score object you create, even if you're just using the object for data storage. If you don't want it to go in your user's timeline you can set the no_feed_story property to hide it. Then if the user explicitly wants to share a score maybe have an extra, "normal" action type? (I think multiple actions on an object are fine as long as only one's visible).

There also seems to be an implicit og.posts action that gets created whenever you create a user-owned object, so you could query by that too, but then you have to filter the "posts" that are specifically for your object type.

Upvotes: 2

Related Questions