我正在尝试为facebook应用添加类似的门。我正在使用最新的facebook PHP SDK,但即使页面被喜欢,也会显示封闭内容。代码如下:
<?php
require 'facebook.php';
$app_id = "xxxxxx";
$app_secret = "xxxxxxxxxx";
$loginNextPage = 'http://www.facebook.com/KillegarStables/'.'?sk=app_'.$app_id;
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
'cookie' => true
));
$signed_request = $facebook->getSignedRequest();
$page_id = $signed_request["page"]["id"];
$like_status = $signed_request["page"]["liked"];
if ($like_status) {
// FOR FANS
$session = $facebook->getSession();
$loginUrl = $facebook->getLoginUrl(
array(
'canvas' => 1,
'fbconnect' => 0,
'next' => $loginNextPage,
'req_perms' => 'publish_stream,photo_upload,user_photos,user_photo_video_tags'
)
);
$fbme = null;
if (!$session) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
else {
try {
$access_token = $facebook->getAccessToken();
$fbme = $facebook->api('/me');
$user = $facebook->getUser();
$url = "https://graph.facebook.com/".$user;
$info = file_get_contents($url);
$info = json_decode($info);
$vars = "id=$user&first_name=$info->first_name&last_name=$info->last_name&access_token=$access_token&pathToServer=$pathToServer&appName=$appName";
} catch (FacebookApiException $e) {
echo "<script type='text/javascript'>top.location.href = '$loginUrl';</script>";
exit;
}
// Begin Like Gated Content.
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" href="style.css" type="text/css" charset="utf-8" />
</head>
<body>
<script language="JavaScript">
<!--
/***********************************************
Script to validate form
***********************************************/
function formCheck(formobj){
// Enter name of mandatory fields
var fieldRequired = Array("animal", "email", "name", "terms");
// Enter field description to appear in the dialog box
var fieldDescription = Array("Answer", "E-mail", "Name", "Agree to Terms and Conditions");
// dialog message
var alertMsg = "Please complete the following fields:\n";
var l_Msg = alertMsg.length;
for (var i = 0; i < fieldRequired.length; i++){
var obj = formobj.elements[fieldRequired[i]];
if (obj){
switch(obj.type){
case "select-one":
if (obj.selectedIndex == -1 || obj.options[obj.selectedIndex].text == ""){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "select-multiple":
if (obj.selectedIndex == -1){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
case "text":
case "textarea":
if (obj.value == "" || obj.value == null){
alertMsg += " - " + fieldDescription[i] + "\n";
}
break;
default:
}
if (obj.type == undefined){
var blnchecked = false;
for (var j = 0; j < obj.length; j++){
if (obj[j].checked){
blnchecked = true;
}
}
if (!blnchecked){
alertMsg += " - " + fieldDescription[i] + "\n";
}
}
}
}
if (alertMsg.length == l_Msg){
return true;
}else{
alert(alertMsg);
return false;
}
}
// -->
</script>
<div id=main>
<div id=comp>
<div id=top>
Answer the following question to be in with a chance of winning a voucher for 2 riding lessions at the lovely Killegar Stables. The lucky winner will be announced on Christmas Eve, and notified by e-mail.</div>
<div id=question><p>What Animal Pulls Santa's Sleigh?</p></div>
<form method='post' action='update.php' onSubmit="return formCheck(this);">
<div id=answer>
<input type='radio'& name='animal' value='Donkey'gt; />Donkey<br />
<input type='radio'& name='animal' value='Horse'gt; />Horse<br />
<input type='radio'& name='animal' value='Reindeer'gt; />Reindear<br />
</p></div>
<label for='email'>E-mail </label>
<input type='text' name='email' id='email' size="50"/><br /><br>
<label for='name'>Name </label>
<input type='text' name='name' id='name' size="50"/>
<br />
<div id="tc"><a href="javascript: alert('1. Acceptance of these terms and conditions is a condition of entry and the entry instructions form part of these terms and conditions. By entering into the competition you agree to be legally bound by these terms and conditions. Killegar Stables reserve the right, at their discretion, to exclude entrants and/or any winner if she/he does not comply with any of these terms and conditions. \n
2. No purchase is necessary for entry. Competition entry is via the Killegar Stables Facebook page. The Christmas competition involves answering a simple questions of what animal pulls Santas sleigh. There are 3 answers to choose from. Users are asked for email address and their name to enter the competition. \n
3. The competition will run from the 16th November until the 24th December, Monday to Sunday inclusive. All daily entrants will go into the draw. \n
4. A panel of judges will choose the winner on the 24th and contact the winner by email. This will be announced on Facebook oon the Killegar page. Killegar Stables reserve the right to judge the correct answer with regard to the skills test element to the competition.
5. There will be one winner of the competition. All entrants will automatically be entered into the draw for the prize.\n
6. There will be one overall prize winner. \n
7. The lessons which are the prize must be taken as part of a group lesson in Killegar Stables. \n
8. The winner is not entitled to use these lessons in relation to any pther product offering from Killegar stables or as a private lesson.
9. The prize may not be exchanged for a cash value. \n
10. Entry to the competition will close on Friday 23rd December at 10.30am. The overall winner to be announced between Saturday 24th between 5pm and 12 midnight \n
11. The winners will be contacted via the email address provided at entry. In the event any prize winner does not communicate his/her acceptance of the prize within 24 hours of notification or cannot be located within this period, Killegar Stables reserve the right to select an alternative prize winner(s) (and the person not responding will waive his/her rights to the prize or forfeit the prize). \n
12. The email address provided by entrants will only be used for communication purposes by Killegar Stables and winners of the competition. All entries email addresses will be added to an email newsletter for sole use by killegar Stables and no pother parties. \n
13. Any delay in waiting for acceptance from winners (within the stated 24 hour period) may affect the announcing of the winners. Killegar Stables can accept no responsibility for this delay. \n
14. The finalists may be required to participate in publicity arising from this promotion including their name & profile picture being featured on the Killegar Stables Facebook wall. \n
15. No applications from agents, third parties, organised groups or applications automatically generated by computer will be accepted. Entries not in accordance with the entry instructions will not be accepted. \n
16. The Facebook competition is open to all registered Facebook users, resident in the Island of Ireland over the age of 6 except employees of Killegar Stables, their families and anyone professionally involved with this competition. \n
17. The decision made in relation to the prize winner will be final and binding on the entrants and no correspondence will be entered into. Killegar Stables accept no responsibility for any disappointment incurred or suffered as a result of any entrant entering the competition or accepting a prize. \n
18. In the event of any dispute the decision of Killegar Stables is final. In the event of unforeseen circumstances Killegar Stables reserves the right to substitute the prize for an alternative of equal or greater value. No correspondence will be entered into.\n
19. Killegar Stables reserve the right to change, alter or withdraw the promotion at any time. Acceptance of the rules is a condition of entry and the entry instructions form part of the rules. \n
20. Responsibility is not accepted for entries lost, damaged or delayed as a result of any network, computer hardware or software failure of any kind. \n
21. To the maximum extent permitted by the law, Killegar Stables shall not be liable for any claims or actions of any kind whatsoever for damages or losses to persons and property which may be sustained in connection with the receipt, ownership and/or use of the prize. \n
22. Killegar Stables shall not be liable for any loss, damage or consequential damage of any nature in contract, tort (including negligence) or otherwise caused by acceptance of the terms and conditions or in connection with the Prize (to the extent permissible by law). \n
23. By entering the promotion, all entrants will be deemed to have accepted and be bound by the rules and consent to the transfer of their personal data to Killegar Stables for the purposes of the administration of this promotion and any other purposes to which the entrant has consented. All entry instructions form part of the rules. If any of these terms and conditions are found by a competent court or other competent authority to be void or unenforceable, that term or condition shall be deemed to be deleted and the remaining terms and conditions shall continue in full force and effect. \n
24. These terms and conditions shall be governed by Irish law and the courts of Republic of Ireland shall have exclusive jurisdiction. \n
25. This promotion is in no way sponsored, endorsed or administered by, or associated with, Facebook. You are providing your information to Killegar Stables and not to Facebook. The information you provide will only be used on within our Facebook page.\n
Promoter and Data Controller: Killegar Stables, The Scalp, Enniskerry Village, Co. Wicklow.
')">Terms and Conditions</a>. Tick here to confirm you agree
<label for='confirm you agree'></label>
<input type='checkbox' name='terms' id='terms' /></div><br>
<div id=enter><input name='enter' type='submit' value='Enter' /></div>
</form></p>
</div>
</div>
</body>
</html>
<?
}
}
else {
// FOR NON FANS
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<img src='images/Killegar_comp.jpg'>
</body>
</html>
<?
}
?>
我对这个问题感到困惑。我已经看到提到导致问题的.htaccess
,但没有提到解决方案。
答案 0 :(得分:1)
FB的文档说getSignedRequest
返回一个字符串,而不是一个数组。
http://developers.facebook.com/docs/reference/php/facebook-getSignedRequest/
更多信息:
http://developers.facebook.com/docs/authentication/signed_request/
正如第二个链接所示,在不使用FB的php sdk的情况下完成此部分(解码请求)非常容易。