[英]Uncaught OAuthException: (#200), when trying to post on wall
I want to implement a simple posting of messages from my DB to my facebook's wall.我想实现从我的数据库到我的 facebook 墙上的简单消息发布。 Using php-SDK:使用 php-SDK:
require_once 'lib/facebook.php';
$appID = 'xxx';
$secret = 'yyy';
$facebook = new Facebook(array(
'appId' => $appID,
'secret' => $secret,
));
$user = $facebook->getUser();
if (empty($user)) {
header("Location: ". $facebook->getLoginUrl(array(
'req_perms' => 'publish_stream',
)));
exit();
}
$params = array(
'message' => 'Hello, every one!',
);
$post_id = $facebook->api('/'. $user .'/feed', 'post', $params);
And i have "Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action thrown in...".而且我有“未捕获的 OAuthException:(#200)用户尚未授权应用程序执行引发的此操作......”。
If I'm not logged in, then when run this script, redirecting to the facebook login.如果我没有登录,那么当运行这个脚本时,重定向到 facebook 登录。 Сonfirm the use of the data is not given. Сonfirm 未给出数据的使用。
Here's a working snippet, but make sure you've downloaded the latest PHP SDK ie 3.0.1 If you don't have already, then download it from here: https://github.com/facebook/php-sdk/这是一个工作片段,但请确保您已经下载了最新的 PHP SDK 即 3.0.1 如果您还没有,请从此处下载: Z5E056C500A1C4B6A7110.com/facebook/php-BADEkZ8
If you go through the codes below, you'll pretty much understand what it does, so i don't think i have to explain you more?如果您通过下面的代码 go ,您将非常了解它的作用,所以我认为我不必向您解释更多?
<?php
// Requires Facebook PHP SDK 3.0.1: https://github.com/facebook/php-sdk/
require ('facebook.php');
define('FACEBOOK_APP_ID',"YOUR-APP-ID");
define('FACEBOOK_SECRET',"YOUR-APP-API-SECRET");
$user = null;
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true
));
$user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected.
if($user == 0) {
/**
* Get a Login URL for use with redirects. By default, full page redirect is
* assumed. If you are using the generated URL with a window.open() call in
* JavaScript, you can pass in display=popup as part of the $params.
*
* The parameters:
* - redirect_uri: the url to go to after a successful login
* - scope: comma separated list of requested extended perms
*/
$login_url = $facebook->getLoginUrl($params = array('scope' => "publish_stream"));
echo ("<script> top.location.href='".$login_url."'</script>");
} else {
try {
$params = array(
'message' => "Hurray! This works :)",
'name' => "This is my title",
'caption' => "My Caption",
'description' => "Some Description...",
'link' => "http://stackoverflow.com",
'picture' => "http://i.imgur.com/VUBz8.png",
);
$post = $facebook->api("/$user/feed","POST",$params);
echo "Your post was successfully posted to UID: $user";
}
catch (FacebookApiException $e) {
$result = $e->getResult();
}
}
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.