Dynamically generate a description for a clearly open open chart using the FB.ui Share dialog

Of all the studies that I have done on this topic, 90% of them are out of date, and this leads me to believe that there have been recent changes to the Facebook JS SDK regarding the frank sharing of Open Graph stories. I have the following code:

function postToFB(desc){ FB.ui({ method: 'share_open_graph', action_type: 'mynamespace:myaction', action_properties: JSON.stringify({ myobject: "myobjectid" }) }, function(response){}); } 

The problem is that he will try to exchange myobject only with the settings that I set in the Facebook Open Graph section in the settings of my application. I would like to use the same object, but I change the description with the dynamic variable "desc" each time it is used together. Does anyone know how to do this? I can statically install Caption in my Facebook Open Graph section in the settings of my application, but I need to dynamically install it every time I share it.

I searched through the Facebook JS SDK for additional key / value pairs that can be added to action_properties, but the SDK information is very limited in this regard.

UPDATE

I changed the code to include 2 calls, one to create an object, and the second to publish a story with new information about the object. Here is the code:

 function postToFB(desc){ FB.api( 'me/objects/mynamespace:myobject', 'post', { object: { "app_id": myappid, "type": "mynamespace:myobject", "url": "myurl", "title": "mytitle", "image": "myimgurl", "description": desc } }, function(response) { console.log(response); FB.ui({ method: 'share_open_graph', action_type: 'mynamespace:myaction', action_properties: JSON.stringify({ myobject: response.id }) }, function(r){}); }); } 

However, according to comments on this subject: Facebook API - duplicate objects created , a Facebook employee said that this approach will not be approved by Facebook, because one action the user cannot create two messages that this code now makes. One of them will send the object to the Facebook user's activity log, and one will send it to the activity log and to the news feed.

It would be nice if I could just make one call and indicate that the description of myobject should be from the FB.ui function itself. Does anyone know how to do this?

+5
facebook facebook-graph-api facebook-javascript-sdk facebook-opengraph
May 01 '14 at 12:19
source share
1 answer

I get it. The main problem that I encountered was to send me / objects (which will put the event into the user's activity log) when I had to send to the application / objects (which would create an object but not send an event). Since publishing an application / application requires an access token, I had to change the initial server call to PHP:

 $request = new FacebookRequest( null, 'POST', '/app/objects/mynamespace:myobject', array( 'access_token' => 'myaccesstoken', 'object' => json_encode(array( 'app_id' => myappid, 'url' => 'myurl', 'title' => 'mytitle', 'image' => 'myimg', 'description' => 'mydesc' )) ) ); $response = $request->execute(); $obj = $response->getGraphObject(); echo $obj->getProperty('id'); 

From there, I could use a JS script to post the object with the new ID in the user channel.

Hope that keeps you from spending 2 and a half days trying to figure it out on your own, just like me.

+5
May 4 '14 at 22:27
source share



All Articles