我已经在我的Facebook App的Open Graph模块中成功创建了一个故事。
故事是:
“约翰[挑选] [巴西]成为MYDOMAIN世界杯足球赛的新世界冠军”
[pick]是动作,[country]是用户选择的国家。这似乎工作正常。但下一步让我感到困惑。
我希望在我的网站上通过Facebook登录的访问者点击他们认为将赢得即将到来的世界杯的国家标志。随后,上述故事发布到他们的时间表。
我不知道如何设置它。 Facebook的开发中心是广泛的,但对于像我这样的PHP新手来说,这个步骤并不是很清楚。
我假设我页面上的标志所代表的超链接需要看起来像这样:
http://mydomain.com/storypublisher.php?&country=“Brazil”& image =“Brazilflag.jpg”等。
所以我的问题是:
我已经阅读过有关“食谱”等的各种教程,但是当你真正开始发布上述故事时,他们让我感到困惑。
答案 0 :(得分:0)
喜欢这个?根据您对代码部分的需求采用它。使用Facebook PHP SDK。
// 0. We don't need to clear session
require_once realpath(dirname(__FILE__)) . 'facebook.php';
$facebook = new Facebook(array(
'appId' => '',
'secret' => '',
));
$fbCurrentUserID = $facebook->getUser();
// 1. If we cant get the user log him in and request permissions This requests combined permissions (basic + post)
if (!$fbCurrentUserID){
$loginUrl = $facebook->getLoginUrl(array(
'scope' => 'publish_actions',
'redirect_uri' => $current_url, // Replace here
));
$this->abortToUrl($loginUrl);
}
// 2. So we do have a current FB user. Lets try to read data (Maybe he declined perms)
try {
// 2.a Check if has granted us the perms and post
$isGranted = $facebook->api(array(
"method" => "users.hasAppPermission",
"ext_perm" => "publish_actions",
"uid" => $fbCurrentUserID,
));
if (!$isGranted){
$login_url = $facebook->getLoginUrl(array(
'scope' => 'publish_actions',
'redirect_uri' => $current_url // Replace here
));
die(header('Location: '. $login_url .''));
}
$res = $facebook->api('/me/feed', 'POST', array(
'link' => '', // Replace and fill with your params
'name' => '', // Replace and fill with your params
'message' => '', // Replace and fill with your params
'description' => '', // Replace and fill with your params
'picture' => '', // Replace and fill with your params
));
} catch (FacebookApiException $e) {
// 2.b Log any error and retry please
die(header('Location: /'));
}
到目前为止,使用一个小表格发布到Facebook控制器。如果传递大量数据,请从$ _GET中选择$ _POST。然后从控制器获取它们并填写我在代码中留下的replace here
注释。如果你是PHP新手,你将需要进一步的指导。在我的拙见中,从facebook SDK控制器开始是错误的开始。好吧,我可能错了。