Facebook Share Dialog failing to recognize custom reference objects when posting custom Open Graph story

ぃ、小莉子 提交于 2019-12-06 07:43:19

问题


So I have a Facebook webpage app, and I'm trying to use the Facebook Javascript SDK and the FB.ui function to post a custom Open Graph story on a user's wall.

I have a custom action 'Ride' and custom object 'Distance'. I am trying to post a custom story 'Ride a Distance'.

My function below is triggered on the click of a button:

function postDistanceRidden() {
  FB.ui({
    method: 'share_open_graph',
    action_type: 'APP_NAME:ride',
    action_properties: JSON.stringify({
        distance:{
          "og:type" : "APP_NAME:distance",
          "app_id" : "APP_ID",
          "og:url" : 'PUBLIC_URL',
          "og:title" : "My Title",
          "og:image" : "PUBLIC_IMAGE_URL",
          "APP_NAME:distance_value" : "10",
          "APP_NAME:distance_unit" : "miles",
        },
    })
  }, function(response){});
}

When I click the button and run the function above, I get a Facebook popup window with the following error: "Action Requires At Least One Reference: The action you're trying to publish is invalid because it does not specify any reference objects. At least one of the following properties must be specified: distance."

I'm not sure what I'm doing wrong. Furthermore, I have tried the above code with replacing my custom actions/objects with Facebook defined ones, and it worked (for example, 'liking' an 'article'). Any help would be greatly appreciated. Please tell me if I need to provide more information.

Thanks!


回答1:


You need to create a "self-hosted object" and pass the url of your object.

function postMyAction() {
    FB.ui({
         method: 'share_open_graph',
         action_type: 'APP_NAME:action',
         action_properties: JSON.stringify({
             object: "my_url_object"
         },
    })
    }, function(response){});
}

And in object html:

<head>
    <meta property='fb:app_id' content='app_id'/>
    <meta property='og:type' content='my_app:object'/>
    <meta property='og:title' content='my_object_title'/>
    <meta property='og:image' content='an_image'/>
    <meta property='og:url' content='self_url'/>
</head>


来源:https://stackoverflow.com/questions/23641355/facebook-share-dialog-failing-to-recognize-custom-reference-objects-when-posting

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!