Publish Facebook Open Graph stories with a friend profile
This post involves the use of the use of the Facebook plugin for Cocos2d-x, that is Ezisocial.
You must have seen open graph stories from Candy Crush Saga in which they publish about a Facebook user passed another user (who is friend) in the game. It looks like the screenshots shown below:
With EziSocial Plugin it is relatively simple to publish such open graph stories. Let’s take a look now.
You must read my other tutorials on open graph stories before reading this tutorial otherwise you may get confuse at some point.
In this tutorial and sample app, we will try to publish a open graph story that will describe that a Facebook User (that is me) has defeated a another user (my friend) on EziSocialDemo app. It will look like as shown in below picture.
Are you interested now? Cool ! Let’s begin the tutorial.
Here are steps to build action with a profile kind of story:-
- Create a open graph story and action with a profile
- Set EziFacebookDelegate as super class
- Define virtual method for callback
- Call function publishOpenGraphActionWithFriend
- Understanding response in callbacks
- Viewing published open graph story
Step 2, 3, 5, and 6 are same as described in tutorial “Publish Open Graph Stories“. So I would not be repeating here. I will describe only step #1 and step #4 to keep brevity of the tutorial.
Step 1: Create a open graph story and action with a profile
For this type of story, we need to build special kind of story with a profile. Go to your apps and then go to stories (will be showing in left pane). Lets create a new story.
A pop will be shown (see picture below) and create your desired action:pass or defeat or anything you like. Now in second table you must selectprofile.
Go ahead and create the story. Edit the story as per your need otherwise it is good to go and lets save the story. Now you can follow the step 2 andstep 3 from previous tutorial. If you have already done with that then lets jump on step 4.
Step 4: Call function publishOpenGraphActionWithFriend
We have a special function for this: publishOpenGraphActionWithFriend
It has only two parameters:
void EziSocialObject::publishOpenGraphActionWithFriend(const char* friendID, const char* actionType)
friendID – Facebook ID of user’s friend. Make sure it is valid Facebook User ID
actionType – In our case action is defeat
Let’s see a example code:
EziSocialObject::sharedObject()->publishOpenGraphActionWithFriend(“090379379120”, // Replace with user’s Facebook Friend ID
EziSocialObject::sharedObject()->logEvent(“Defeat a friend”);
That’s it. If you have configured callback properly then you will see the response within the game.