简体   繁体   中英

Facebook: show open graph dialog when posting expects object reference

I want to show the open graph dialog to allow users to write a message before post on their timeline. I'm trying to use the share_open_graph dialog but for some reason it says that the action is not referencing the object.

I know that there are some questions about it, but it didn't help me. Also, I would like to know why my second code works (I know that not shows the dialog) and why the first one no, and when I find the solution, why this solution.

This is my code using the Facebook open graph dialog:

FB.ui({
    method: 'share_open_graph',
    action_type: 'alexdecasa:decorate',
    action_properties: JSON.stringify({
        room: {
            "url": image,
            "title": "Supply title",
            "description": "Supply description",
            "image": image
        }
    })
}, function(response){});

My action is decorate and the object is room . As you can see I'm referencing the object inside the action_properties.

Using FB.api code works:

FB.api(
    'me/alexdecasa:decorate',
    'post',
    {
        room: {
            "url": image,
            "title": "Supply title",
            "description": "Supply description",
            "image": image
        }
    },
    function(response) {});

I found the solution. I needed to create the app in an external PHP file and put the meta tags that provides my object.

Now with the javascript code like this i can share it without any problem:

    FB.ui({
        method: 'share_open_graph',
        action_type: 'alexdecasa:decorate',
        action_properties: JSON.stringify({
            room:url
        })
    }, function(response){
        console.log(response);
    });

As Alejandro-bar figured out, that is the correct way to call the share dialog with Open Graph objects.

FB.ui({
  method: 'share_open_graph',
  action_type: 'alexdecasa:decorate',
  action_properties: JSON.stringify({
      room:'url-to-my-room',
  })
}, function(response){});

The URL from the object you're going to share should include the pertinent open graph metatags in order for the share to work correctly.

The pertinent Facebook documentation is here: https://developers.facebook.com/docs/sharing/reference/share-dialog

Important step: Include open graph meta tags on the page at this URL to customize the story that is shared back to Facebook.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM