用facebook php sdk在时间轴上发布动作

时间:2012-03-04 22:57:52

标签: php facebook facebook-graph-api

<?php
require "src/facebook.php";

$facebook = new Facebook(array(
'appId'=>'xxxxxxxxx',
'secret'=>'xxxxxxxxxxxxxxxxx',
'cookie'=>true
));

if(!$facebook->getUser())
{
$url = $facebook->getLoginUrl(array('scope'=>'email,publish_actions'));
echo "<script> top.location=\"".$url."\"; </script>";
exit(0);
}

$params = array('article'=>'http://www.xxxxxxxxx.com/script/','access_token'=>$facebook->getAccessToken());

$out = $facebook->api('/me/namespace:read','post',$params);

print_r($out);

exit(0);

?>

但是我有一些问题,我应该把这些元标记放在哪里?我只找到了javascript示例,我还有另一个问题如何使用动态网址:

http://www.xxxxxxxxx.com/script/?article_id=xxxx

如果我尝试在此url中放入一些参数,则会返回错误,如:

Fatal error: Uncaught OAuthException: (#3502) Object at URL http://www.xxxxxxxxx.com/script/?article_id=xxxx has og:type of 'website'. The property 'article' requires an object of og:type 'namespace:article'. thrown in xxxxxxx on line 1106

感谢。

1 个答案:

答案 0 :(得分:1)

http://www.xxxxxxxxx.com/script/?article_id=xxxx&lt; head&gt; 部分中,您应该添加以下内容:

<head>
    <title>My article</title>
    <meta property="og:title" content="My article" />
    <meta property="og:type" content="namespace:article" />
    <meta property="og:url" content="http://www.xxxxxxxxx.com/script/?article_id=xxxx" />
    <meta property="og:image" content="http://www.xxxxxxxxx.com/image.jpg" />
    <meta property="fb:app_id" content="xxxxxxxx" />
    <meta property="og:description" content="My wonderful article" />
</head>

从错误消息中的命名空间我猜测你定义了自己的文章对象而没有使用builtin article object

相关问题