通过 FB.ui Share Dialog 为显式共享的开放图故事动态生成描述 [英] Dynamically generate description for explicitly shared open graph story through FB.ui Share Dialog

查看:23
本文介绍了通过 FB.ui Share Dialog 为显式共享的开放图故事动态生成描述的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我就该主题所做的所有研究中,90% 已经过时,这让我相信 Facebook JS SDK 最近在明确共享 Open Graph 故事方面发生了变化.我有以下代码:

Of all of the research I've done on this topic, 90% of it is outdated, which brings me to believe there have been recent changes to the Facebook JS SDK regarding explicitly sharing 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){});
}

这样做的问题是它会尝试仅使用我在应用设置的 Facebook Open Graph 部分中设置的设置来共享 myobject.我想使用相同的对象,但每次共享时使用动态desc"变量更改描述.有谁知道如何做到这一点?我可以在我的应用设置的 Facebook Open Graph 部分静态设置标题,但我需要在每次分享时动态设置它.

The problem with this is that it will attempt to share myobject with only the settings I've set up in the Facebook Open Graph section of my app settings. I would like to use the same object, but change the description with a dynamic 'desc' variable each time it's shared. Does anyone know how to accomplish this? I can statically set the Caption in my Facebook Open Graph section of my app settings, but I need to dynamically set it every time I share it instead.

我已经通过 Facebook JS SDK 搜索了可以添加到 action_properties 的其他键/值对,但 SDK 信息在这方面非常有限.

I've 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.

更新

我修改了代码以包含 2 个调用,一个用于创建对象,第二个用于发布包含新对象信息的故事.代码如下:

I've modified the code to include 2 calls, one to create the object and the second to publish the story with the new object's information. Here's 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){});
});
}

但是,根据对这个问题的评论:Facebook 对象 API - 已创建重复对象 Facebook 的一名工作人员表示,这种方法不会得到 Facebook 的批准,因为用户的一个操作不能产生两个帖子,而这段代码现在可以这样做.一个将对象发布到 Facebook 用户的活动日志,另一个将其发布到活动日志和新闻提要.

However, according to the comments on this question: Facebook object API - duplicate objects created a Facebook staff member said this approach will not be approved by Facebook because one action by a user cannot produce two posts, which this code now does. One will post the object to the Facebook user's activity log, and one will post it to the activity log and the news feed.

如果我可以只进行一次调用并从 FB.ui 函数本身规定 myobject 描述应该是什么就好了.有人知道怎么做吗?

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

推荐答案

我想通了.我遇到的主要问题是当我应该发布到应用程序/对象(它会创建对象但不会发布事件)时,我正在发布给我/对象(这会将事件发布到用户的活动日志).由于发布到应用程序/任何东西都需要访问令牌,因此我不得不更改在 PHP 服务器端发生的初始调用:

I figured it out. The main problem I was having is I was posting to me/objects (which would post an event to the user's activity log) when I should have been posting to app/objects (which would create the object but not post an event). Since posting to app/anything requires an access token, I had to change the initial call to happen on the server side in 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');

从那里我可以使用 JS 脚本将具有新 ID 的对象发布到用户的供稿中.

From there I could use the JS script to post the object with the new ID to the user's feed.

希望这能阻止您像我一样花费 2 天半的时间试图自己解决问题.

Hope that prevents you from spending 2 and a half days trying to figure it out on your own like I did.

这篇关于通过 FB.ui Share Dialog 为显式共享的开放图故事动态生成描述的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆