简体   繁体   中英

Posting action on timeline with facebook php sdk

<?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);

?>

But i got some questions, where should i put these meta tags? i only found javascript examples and i got another question how to use a dynamic url like:

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

if i try to put some parameter in this url it returns error like:

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

thanks.

Within the section of http://www.xxxxxxxxx.com/script/?article_id=xxxx you should add something like this: 部分中,您应该添加以下内容:

<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>

From the namespace in the error message I'm guessing that you defined your own object and didn't use the builtin article object . 对象,并没有采用内置的文章对象

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM