我正在尝试使用新的图形 API 和 PHP 将消息发布到用户的墙上。连接似乎工作正常,但没有出现任何帖子。我不确定如何正确设置发布代码。请帮帮我。抱歉,看起来很糟糕的代码,出于某种原因,StackOverflow 不想在代码块中将其全部关闭。
下面是我的完整代码。我是否缺少扩展程序权限请求,或者是否在这段代码中得到了注意:
PHP代码
<?php
include_once 'facebook.php';
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'cookie' => true
));
$session = $facebook->getSession();
if (!$session) {
$url = $facebook->getLoginUrl(array(
'canvas' => 1,
'fbconnect' => 0
));
echo "<script type='text/javascript'>top.location.href = '$url';</script>";
} else {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
$updated = date("l, F j, Y", strtotime($me['updated_time']));
echo "Hello " . $me['name'] . "<br />";
echo "You last updated your profile on " . $updated;
$connectUrl = $facebook->getUrl(
'www',
'login.php',
array_merge(array(
'api_key' => $facebook->getAppId(),
'cancel_url' => 'http://www.test.com',
'req_perms' => 'publish_stream',
'display' => 'page',
'fbconnect' => 1,
'next' => 'http://www.test.com',
'return_session' => 1,
'session_version' => 3,
'v' => '1.0',
), $params)
);
$result = $facebook->api(
'/me/feed/',
'post',
array('access_token' => $facebook->access_token, 'message' => 'Playing around with FB Graph..')
);
} catch (FacebookApiException $e) {
echo "Error:" . print_r($e, true);
}
}
?>
最佳答案
这是因为您没有指定“req_perms”并允许应用程序将流发布到您的墙上。确保在“req_perms”中添加“publish_stream”。
PHP代码:
$url = $facebook->getLoginUrl(array(
'canvas' => 1, //set to 1 bcoz my application is Iframe app
'fbconnect' => 0,
'req_perms' => 'publish_stream'
));
关于php - 使用 Graph API 通过 PHP 发布到 Facebook Stream,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3982171/