我已经成功地在我的Facebook应用程序的开放图形模块中创建了一个故事。
故事是:
约翰在MYDOMAIN世界杯足球赛中被选为新的世界冠军
选择是行动,国家是用户选择的国家。这看起来挺好的。但下一步却让我困惑不解。
我希望那些在我的网站上通过Facebook登录的访问者点击他们认为将赢得即将到来的世界杯的国家国旗。随后,将上述故事发布到他们的时间表上。
我不知道该怎么安排这个。Facebook的开发中心非常广泛,但是对于像我这样的PHP新闻来说,这一步还不太清楚。
我假设页面上的标志所代表的超链接需要如下所示:
http://mydomain.com/storypublisher.php?&country="Brazil"&image="Brazilflag.jpg“等。
所以我的问题是:
我读过关于“食谱”等的各种教程,但当涉及到你真正开始发表上述故事的部分时,它们让我感到困惑。
发布于 2013-12-18 13:20:01
是像这样吗?根据您对代码部分的需要使用它。使用Facebook。
// 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的$_GET。然后从控制器获取它们并填充我在代码中留下的replace here注释。如果您是PHP新手,您需要进一步的指导。在我看来,从facebook控制器开始是个错误的开始。我可能错了。
https://stackoverflow.com/questions/20658083
复制相似问题