我们开发了一个购物网站,我们使用Facebook登录,当客户购买时,我们已经将产品发布在他们的墙上。为了执行此操作,我使用xxx@test.com在developer.facebook.com中创建了一个应用程序。
如果我使用xxx@test.com并登录我的网站并购买产品它正在发布到Facebook墙但是如果我使用不同的帐户获取例外
user not authorized application
我开始谷歌搜索,最后我提交了publish_actions审核权限
这是否是在fb墙上发布的唯一方式?为什么单独发布xxx@test.com?
以下是我使用的代码
public function postFbWall($customer_name) {
if(!isset($this->fbconnect)) {
require_once(DIR_SYSTEM . 'vendor/facebook-sdk/facebook.php');
$this->fbconnect = new Facebook(array(
'appId' => $this->config->get('fbconnect_apikey'),
'secret' => $this->config->get('fbconnect_apisecret'),
"cookie"=>true,
));
$_SERVER_CLEANED = $_SERVER;
$_SERVER = $this->clean_decode($_SERVER);
}
$fbuser = $this->fbconnect->getUser();
if($fbuser){
try {
$fbuser_profile = $this->fbconnect->api("/$fbuser");
$access_token = $this->fbconnect->getAccessToken();
$message = "First three users who registers through this links will get 5% of the product price as reward points";
$attributes = array(
'name' => $customer_name,
'caption' => HTTP_SERVER,
'access_token' => $access_token,
'message' => 'message goes here',
'link' => 'link',
'description' => 'description goes here',
);
$ch = curl_init();
$purl = "https://graph.facebook.com/".$fbuser."/feed";
$mattr = "";
foreach($attributes as $key=>$value):
$mattr .= $key."=".$value."&";
endforeach;
curl_setopt($ch,CURLOPT_URL,$purl);
curl_setopt($ch,CURLOPT_POST,count($attributes));
curl_setopt($ch,CURLOPT_POSTFIELDS,$mattr);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch,CURLOPT_VERBOSE ,true);
$res = curl_exec($ch);
curl_close($ch);
$resultobj = json_decode($res);
if(isset($resultobj->id)) { $res =true;} else {$res=false;}
} catch (FacebookApiException $e) {
error_log($e);
$fbuser = null;
}
}
}