简体   繁体   English

Facebook:发布时显示打开的图形对话框,需要对象引用

[英]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. 我正在尝试使用share_open_graph dialog但是由于某种原因,它表示该操作未引用该对象。

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: 这是我使用Facebook打开图对话框的代码:

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 . 我的动作是decorate ,物体是room As you can see I'm referencing the object inside the action_properties. 如您所见,我正在引用action_properties中的对象。

Using FB.api code works: 使用FB.api代码的工作原理是:

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. 我需要在外部PHP文件中创建应用程序,然后将提供我的对象的meta标记放入。

Now with the javascript code like this i can share it without any problem: 现在,使用这样的javascript代码,我可以毫无问题地共享它:

    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. 正如Alejandro-bar所指出的那样,这是使用“打开图”对象调用共享对话框的正确方法。

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. 您要共享的对象的URL应包含相关的打开图元标记,以使共享正常工作。

The pertinent Facebook documentation is here: https://developers.facebook.com/docs/sharing/reference/share-dialog 相关的Facebook文档在此处: 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. 重要步骤:在此URL的页面上包括开放图元标记,以自定义共享回Facebook的故事。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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