我在发布这个问题之前搜索了一个小时,如果这是一个基本的密集问题,请提前原谅我。我觉得必须有一些简单的东西,我不会把头包裹起来。
我看到很多应用,例如“WeForPresident”加入后,发布一个简单的feed。它不包含特殊格式,只包含图像,指向外部网站的链接和一些文本。
我找不到使用图形api执行此操作的方法。当我使用链接参数发布时,我得到“共享链接”格式,这是不希望的。然而,使用消息参数不允许链接。
那么,WeForPresident等应用程序如何实现这种效果呢?
再次感谢。
Bounty Info
使用/ TEST_USER_ID / feed与消息,链接,描述,图片,名称
帖子作为链接
添加了动作参数
有问题的应用程序用户谈论
注意在帖子中的任何地方都没有提到分享
答案 0 :(得分:6)
你在谈论这样的事吗?
通过开放图形对象和动作可以实现这一点。这是一个简短的(并且希望不是非常令人困惑)细分:
对象:在上图中,对象是“需要家的宠物”。对象是用于描述您正在分享的页面的文本,并且在您共享的页面的标题标记中引用(稍后会详细介绍。)
动作:在上图中,指的是“... 共享需要家庭的宠物......”中的“共享”。动作就是你用开放图实际做的事情。我已经看到网站“签署请求某某某某”或“播放这样一个关于这个和那个应用程序的单词”。粗体字是动作。
可以在http://developers.facebook.com上定义操作和对象类型。如果/当您有应用程序,并且您选择使用Open Graph时,它会鼓励您创建至少一个操作和一个对象类型。有许多预定义的(“读书”,“烹饪食谱”,“观看视频”等)。操作和对象可以帮助您个性化发布到人们墙上的消息。
值得注意的是,如果你定义一个自定义Action,Facebook需要在他们愿意让任何人使用它之前批准它。通常情况下,这并不是非常困难......您只需点击操作旁边的“提交”按钮,它就会告诉您是否/何时获得批准。
所以现在我们已经掌握了基础知识,让我们谈谈如何在你的网页上实现这样的东西。我确信你很清楚,Open Graph使用FB.api()而不是FB.ui()。我将在这里使用Javascript示例。
FB.api(
'/me/app_namespace:share',
'post',
{
pet_who_needs_a_home: document.location.href,
image: pet_image // optional
},
function(response) {
// You can do something with the response here.
// If successful, Facebook returns the post id of the post it just made
// If it fails, check response.error
}
);
你的< head>中还需要两个非常重要的标签。标签。他们在这里:
<meta property="fb:app_id" content="YOUR_APP_ID" />
<meta property="og:type" content="APP_NAMESPACE:pet_who_needs_a_home" />
现在让我告诉你一切是什么。 FB.api()很明显,所以我会跳到...
'/me/app_namespace:share',
/我发布到你的墙上。 app_namespace是在developers.facebook.com上的应用详细信息部分中找到的命名空间。您可能需要定义命名空间(settings-&gt; basic-&gt; second text box)。 “:”打破命名空间和操作。分享是行动(再次在developers.facebook.com上定义)。
'post',
告诉Facebook我们想要使用POST请求(而不是GET请求)。
{
pet_who_needs_a_home: document.location.href,
image: pet_image // optional
},
这显然是一个包含两个重要值的javascript数组。 “pet_who_needs_a_home”是(实际上我的......你应该用你的任何东西替换它)对象类型(仍然在developers.facebook.com上),你回忆一下,这有助于我们定义所使用的语言,如上图所示。图像是一个可选字段,您可以在其中定义将通过打开图形共享的图像。还有很多其他可选字段,你可以查看......你知道。
function(response) {
......所有这一切都很明显,所以我会在那里留下毫无意义的细节。正如我在评论中提到的,如果成功,它会返回帖子的帖子ID,或者返回错误(在response.error中找到),这可能是也可能不是描述性的。
我希望meta标签能说明问题。 YOUR_APP_ID是......你猜对了......你的应用ID。全数字。 app_namespace再次是您的命名空间。 pet_who_needs_a_home是(我的)对象,应该替换为您正在使用的任何对象。
对不起,很长的帖子。希望有点清楚这一点。
答案 1 :(得分:3)
这将通过您的appName发布与weForPresident完全相同的帖子。请相应更改您的消息。和访问令牌应具有publish_actions扩展权限
$attachment = array(
'access_token' => $access_token,
'message' => "I Just Join WeForPresident",
'name' => "WeForPresident",
'description' => "philippe harewood just started gamng the election on weForPresident and could possibly win some cool stuff",
'link' => "any link to external site",
'picture' => "image link to display in left box"
);
$facebook->api("me/feed","POST",$attachment);
希望它有所帮助。
更新:以上解决方案的javascript对话框将如下所示,这将提示用户发布,因此不需要publish_actions扩展权限:
<html xmlns='http://www.w3.org/1999/xhtml'
xmlns:fb='https://www.facebook.com/2008/fbml'>
<head>
<title>My Feed Dialog Page</title>
</head>
<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p id='msg'></p>
<script>
FB.init({appId: '#############', status: true, cookie: true});
// calling the API ...
var obj = {
method: 'feed',
link: 'any external url',
picture: 'picture url to show up in left',
name: 'name of the post: comes as heading in blue color within box',
description: 'post description, that comes within box'
};
function callback(response) {
}
FB.ui(obj, callback);
</script>
</body>
</html>";
此类帖子的完整代码:首先从https://github.com/facebook/facebook-php-sdk下载php-sdk
<?php
include_once "facebook-sdk/facebook.php";
$facebook = new Facebook(array(
'appId' => APP_ID,
'secret' => APP_SECRET,
));
if(isset($_GET['code']))
{
$access_token = $facebook->getAccessTokenFromCode($_GET['code'],$_SESSION['redirect_uri']);
$facebook->setAccessToken($access_token);
$attachment = array(
'access_token' => $access_token,
'message' => "$message",
'name' => "$name",
'description' => "$description",
'link' => "any external link",
'picture' => "picture url"
);
$facebook->api("me/feed","POST",$attachment);
}
else
{
$scope = "publish_stream";
$params = array('scope' => $scope);
$loginUrl = $facebook->getLoginUrl($params);
echo("<script> top.location.href='" . $loginUrl . "'</script>");
}
?>
答案 2 :(得分:2)
这最终成为一个未修复的错误,并且当前状态为“triaged”
http://developers.facebook.com/bugs/138798476259001
到目前为止,唯一的解决方案似乎是添加动作参数