gpt4 book ai didi

Facebook Javascript SDK : Publish actions with custom Open Graph objects

转载 作者:行者123 更新时间:2023-12-02 22:03:02 25 4
gpt4 key购买 nike

我正在开发我的 Cordova 应用程序以使其更具病毒性。因此,当他们在游戏中存档新内容时,我想包括 Facebook 和 Open Graph API 以在玩游戏的用户的新闻流中发布。我对整个 Facebook 和开放图谱完全陌生,所以请帮助我开始使用它。

我通过运行以下代码登录一个新用户:

$(login).on("click", function() {
FB.login(function() {
console.log("Default Login succeded");
console.log("Asking for write permissions");
FB.login(function(rsp) {
console.log("GOT WRITE PERMISSIONS");
log(rsp);
}, {
scope : 'publish_stream'
});
}, {scope:"email"});

});

我在命名空间 einszwo 下注册了一个名为 buy 的开放图操作。作为对象,我使用默认的 object

Defined open graph action and object

尚未审核,但我正在使用开发者 Facebook 帐户登录我的设备。

现在我想调用这个 Action 。为此,我使用以下代码:

    var obj = {
title : "I visited Google",
url : "http://www.google.com"
};

function callback(response) {
console.log(JSON.stringify(response));
}


FB.api('me/einszwo:buy','POST',obj, callback);

不幸的是,调用失败,来自 Facebook 的响应如下:

{"error":{"type":"Exception",
"message":"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: object.","code":1611072}}

如果有人可以帮助我解决这个问题或提供我的一些信息以便我查找更多信息,那就太好了。

谢谢!

塞巴斯蒂安

编辑

将 url 粘贴为对象的解决方案有效,但我们想使用您在 Facebook Object Browser 中定义的 Facebook 托管对象。该方法是能够发布用户的事件,如果有人点击该事件,我们希望他们被重定向到我们的应用程序信息页面。

我们无法为每个不同的对象提供一个页面。是否可以使用 Facebook Javascript SDK 来使用托管在 facebook 上的预定义对象?

我真的很想有这样的可能性来创建新对象

   var o = {
"og:title" : "Test " + new Date(),
"og:url" : "http://facebook.com/appcenter/**APPNAMESPACE**",
"og:type" : "Object"

}
FB.api('/me/**APPNAMESPACE**:buy', 'POST', {
object : o
}, function(response) { console.log(JSON.stringify(response));});

返回

{"message":"(#3503)\"{\"og:title\":\"2013 年 5 月 23 日星期四 12:19:45 GMT+0300 (EEST)\",\"og:url\":\"http://facebook.com/appcenter/einszwo\",\"og:type\":\"Object\"}\"是属性\"object\"的无效值输入\"Reference\"","type":"OAuthException","code":3503}

或一种使用预定义 facebook 对象 ID 的方法,例如:

    FB.api('1234567890', 'POST', {
}, function(response) { console.log(JSON.stringify(response));});

谁能帮帮我?

谢谢!

最佳答案

听起来您在谈论应用拥有的对象。

An app-owned object. These objects are used across your entire app. They are public, just like self-hosted objects. Anyone who uses your app can see them and they can be attached to any story your app creates.

您不能将您的 appcenter url 用作对象(如果您考虑开放图 URL 的用途,这真的没有意义,并且几乎是对开放图的滥用)

您在 cURL 中或使用对象浏览器创建对象

Leopluradon

在我的例子中,我为我的咖啡店类型创建了一个 Leopluradon 对象。然后我从创建的结果中获得了 id (149831668534005) 并在我的调用中使用了它

FB.api(
'/me/philippeharewood:code',
'post',
{ coffeeshop: '149831668534005' },
function(response) {
if (!response || response.error) {
alert('Error occured');
console.log(response.error);
} else {
alert('Publish was successful! Action ID: ' + response.id);
}
});

可在 http://philippeharewood.com/facebook/charlie.html 找到演示,它对你不起作用,但你明白了要点。

Result in Browser

然后您可以在您的事件中看到它。

Result on Facebook

这一切都在 https://developers.facebook.com/docs/opengraph/using-object-api/ 中进行了解释

关于Facebook Javascript SDK : Publish actions with custom Open Graph objects,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16566557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com