使用 PHP SDK 实现 Facebook 好友选择器对话时遇到的问题
我正在尝试找出如何正确实现应用程序请求的朋友选择器对话。
我的目标是,一旦用户进入我的竞赛应用程序,如果他们没有获胜,他们可以选择向 5 个朋友发送请求,然后他们将有另一次进入的机会。
我不知道是否可以强制选择至少 5 个朋友,但是控制他们是否可以进入的逻辑将由数据库中存储的一些数据控制,即发送请求后,将数据库更新为允许他们重新进入。
我遵循了这个问题中的代码:
如何使用 Facebook 的 PHP sdk 显示朋友选择器对话框?
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXX',
));
$user = $facebook->getUser();
$url = 'https://www.facebook.com/dialog/';
$url .= 'apprequests?app_id=XXXXXXXXXX&redirect_uri=http://www.domain.com/';
$url .= '&message=Share%20with%205%20friends%20for%20another%20chance%20to%20win!&display=popup';
?>
<a href="<?php echo $url; ?>">Recommend friends for another chance to win!</a>
<?php
echo $_GET['request_ids'];
if (isset($_GET['request_ids'])) {
for ($i=0; $i<count(request_ids); $i++){
$link = ($link + "&to=" + $request_ids[$i]);
}
echo "<script language=javascript>parent.location=''</script>";
}
我遇到的问题是,当我单击链接时,Facebook 徽标会出现,并在下面显示“转到 facebook.com”。当我单击此按钮时,对话框将在整页中打开。
如果我单击“取消”,它会将我带到我的域,但它不能重定向到该选项卡吗?
同样,如果我完成应用程序请求对话,当我宁愿重定向到选项卡时,我会被重定向到我的主页。
我很难理解这个问题,所以我们将不胜感激。
总而言之,我希望在弹出窗口中打开对话,而不是突然出现 Facebook 徽标,然后在页面中打开对话。
然后,如果用户单击“取消”以简单地关闭对话框,并且如果请求完成,则对话框将再次关闭,保留选项卡而不是对话框为完整页面并重定向到我的域。
谢谢。
I am trying to figure out how to properly implement the friends selector dialogue for app requests.
What I am aiming for is, once the user has entered my competition app, if they don't win they can choose to send a request to 5 friends and then they will get another chance to enter.
I have no idea if it's possible to enforce a minimum of 5 friends to be selected but the logic for controlling whether they can enter or not will be controlled by some data stored in the database, i.e once the request is sent, update the db to allow them to re-enter.
I followed the code in this question:
How to display the friends selector dialog with PHP sdk for Facebook?
// Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
'appId' => 'XXXXXXXXX',
'secret' => 'XXXXXXXXXXXXXXXXXX',
));
$user = $facebook->getUser();
$url = 'https://www.facebook.com/dialog/';
$url .= 'apprequests?app_id=XXXXXXXXXX&redirect_uri=http://www.domain.com/';
$url .= '&message=Share%20with%205%20friends%20for%20another%20chance%20to%20win!&display=popup';
?>
<a href="<?php echo $url; ?>">Recommend friends for another chance to win!</a>
<?php
echo $_GET['request_ids'];
if (isset($_GET['request_ids'])) {
for ($i=0; $i<count(request_ids); $i++){
$link = ($link + "&to=" + $request_ids[$i]);
}
echo "<script language=javascript>parent.location=''</script>";
}
The problems I am having are that when I click the link, the facebook logo then appears with 'go to facebook.com' underneath. When I click this, the dialogue opens in a full page.
If I click cancel, it takes me to my domain but can it not redirect to the tab?
Likewise, if I complete the app request dialogue I am redirected to my homepage when I would rather be re-directed to the tab.
Having a hard time getting my head around this so help would be greatly appreciated.
To summarise, I would like to have the dialogue open in a popup, rather than the facebook logo suddenly appearing and then the dialogue opening in the page.
Then, if the user clicks 'cancel' for the dialogue to simply close and if the request is completed, for the dialogue to close again, leaving the tab instead of the dialogue being a full page and redirecting to my domain.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 Facebook JS-SDK 将提供您所要求的最佳体验。如果这是一个选项(无法想象为什么它不会),那么您应该使用 请求对话框:
如何处理发送的请求也在文档和我的教程中进行了描述;下面是使用新请求格式处理回调的示例(我使用的是 jQuery):
更新: 至于“最少”好友数量要求。 JS-SDK 对话框有一个
max_recipients
属性,但没有最小值,因此您需要有自己的好友选择器,然后将to
属性设置为这些好友的 ID。Using the Facebook JS-SDK would provide the best experience you are asking for. If that's an option (can't think why it won't be), then you should use the Requests Dialog:
How to handle the requests sent is also described in the documentation and also in my tutorial; below is an example of handling the callback with the new requests format (I'm using jQuery):
UPDATE: As for the "minimum" # of friends requirement. The JS-SDK dialog has a
max_recipients
property but no minimum, so you need to have your own friend selector then set theto
property to those friends' ids.