以下代码在chrome和IE上完美运行但是当我用Firefox测试它时,它返回错误“发生错误,请稍后再试” . 我可以知道代码中的问题是什么,下面是与Facebook API相关的代码 .
$user_id = $facebook->getUser();
if ($user_id) {
try {
// Fetch the viewer's basic information
$basic = $facebook->api('/me');
} catch (FacebookApiException $e) {
// If the call fails we check if we still have a user. The user will be
// cleared if the error is because of an invalid accesstoken
if (!$facebook->getUser()) {
header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
exit();
}
}
if (check_user($user_id,$promo) && check_friend($user_id)>0){
header('Location: Thankyou.php');
}
if (!check_promo()){
header('Location: Thankyou.php');
}
// Fetch the basic info of the app that they are using
$app_info = $facebook->api('/'. AppInfo::appID());
$app_name = idx($app_info, 'name', '');
?>
<!DOCTYPE html>
<html xmlns:fb="http://ogp.me/ns/fb#" lang="en">
<head>
<script type="text/javascript">
function logResponse(response) {
if (console && console.log) {
console.log('The response was', response);
}
}
//Perhaps the problem come from here
$(function(){
// Set up so we handle click on the buttons
$('#postToWall').click(function() {
FB.ui(
{
method : 'feed',
link : $(this).attr('data-url')
},
function (response) {
// If response is null the user canceled the dialog
if (response != null) {
logResponse(response);
}
}
);
});
$('#sendRequest').click(function() {
FB.ui(
{
method : 'apprequests',
message : $(this).attr('data-message')
},
function (response) {
// If response is null the user canceled the dialog
if (response != null) {
var request_ids = [];
var friend_ids = [];
for(i=0; i<response.to.length; i++) {
//var temp = response.to[i] + '_' + response.to[i].name;
request_ids.push(response.request);
friend_ids.push(response.to[i]);
}
var requests = request_ids.join(',');
var friends = friend_ids.join(',');
$.post('friend_handler.php',{uid: <?php echo $user_id; ?>, fid: friends, rid: requests},function(resp) {
});
}
}
);
});
});
</script>
<?php $caption = "Hello";
$description = "Byebye";
?>
<script>
FB.init({appId: "<?php echo AppInfo::appID(); ?>", status: true, cookie: true});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
link: 'http://apps.facebook.com/mas-amazing-journey/',
picture: 'http://www.xman.com/content/mas-admin/my/en/site-configuration/homepagethreatre/book/AmazingWorldwideDeals/_jcr_content/contentpar/masimage_9126.img.jpg/1339349457238.jpg',
name: 'Amazing Journey',
caption: '<?php echo $caption; ?>',
description: '<?php echo $description; ?>'
};
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
</script>
<!--[if IE]>
<script type="text/javascript">
var tags = ['header', 'section'];
while(tags.length)
document.createElement(tags.pop());
</script>
<![endif]-->
<script src="//connect.facebook.net/en_US/all.js"></script>
</head>
<body>
<header class="clearfix">
<div id="fb-root"></div>
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo AppInfo::appID(); ?>', // App ID
channelUrl : '//<?php echo $_SERVER["HTTP_HOST"]; ?>/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Listen to the auth.login which will be called when the user logs in
// using the Login button
FB.Event.subscribe('auth.login', function(response) {
// We want to reload the page now so PHP can read the cookie that the
// Javascript SDK sat. But we don't want to use
// window.location.reload() because if this is in a canvas there was a
// post made to this page and a reload will trigger a message to the
// user asking if they want to send data again.
window.location = window.location;
});
FB.Canvas.setAutoGrow();
};
// Load the SDK Asynchronously
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
<?php if (isset($basic)) { ?>
<p id="picture" style="background-image: url(https://graph.facebook.com/<?php echo he($user_id); ?>/picture?type=normal)"></p>
<h1>Welcome, <strong><?php echo he(idx($basic, 'name')); ?></strong></h1>
<p class="tagline">
Good Luck!
</br>
</p>
<div id="share-app">
<!-- <p>Tools for your to invite your friends and spread your words:</p>-->
<ul>
<li>
<a href="#" class="facebook-button" onclick='postToFeed(); return false;' >
<span class="plus">Share this on my wall</span>
</a>
</li>
<!-- <li>
<a href="#" class="facebook-button speech-bubble" id="sendToFriends" data-url="<?php echo AppInfo::getUrl(); ?>">
<span class="speech-bubble">Share Your Amazing Journey</span>
</a>
</li>-->
<li>
<a href="//<?php echo $_SERVER["HTTP_HOST"]; ?>/Thankyou.php" class="facebook-button speech-bubble" id="thankyou">
<span class="speech-bubble">SUBMIT</span>
</a>
</li>
</ul>
<li>
<a href="#" class="facebook-button apprequests" id="sendRequest"
data-message="I have just invited you to fly with me">
<span class="apprequests"><img border="0" class="facebook-button apprequests" id="sendRequest" src="http://i.imgur.com/lRdP3.jpg" style="width: 680px;margin-top:10px;z-index: -9999;"/></span>
</a>
</li>
</div>
<div id="guides"></div>
<?php } else { ?>
<section id="get-started">
<p>Oops, You're out of track... Please reload the page to start over!</p>
</section>
<?php } ?>
</header>
</body>
</html>
Firefox返回的URL返回错误
https://www.facebook.com/dialog/feed?caption=Amazing%20Journeys%20by%20Malaysia%20Airlines&description=Malaysia%20Airlines%20is%20back%20with%20Amazing%20Journeys%20from%20only%20RM272%20from%2011th %20-%第二千〇一十八%20June%202012.&显示弹出=&链路= HTTP%3A%2F%2Fwww.malaysiaairlines.com%2Fmy%2Fen%2Fdeals%2Fdeals-的最day.html%3Fcid%3D2145&语言环境= EN_US&名称= MAS% 20Amazing%20Journey%20Deals&下一= HTTPS%3A%2F%2Fs-static.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D8%23CB%3Df3bcbdb08f0cb22%26origin%3Dhttps%253A%252F%252Fmas-fb.net% 252Ff3d2f4375cf26%26domain%3Dmas-fb.net%26relation%3Dopener%26frame%3Df23819ec6e183c%26result%3D%2522xxRESULTTOKENxx%2522&图片= HTTP%3A%2F%2Fwww.malaysiaairlines.com%2Fcontent%2Fmas管理员%2Fmy%2Fen%2Fsite-配置%2Fhomepagethreatre%2Fbook%2FAmazingWorldwideDeals%2F_jcr_content%2Fcontentpar%2Fmasimage_9126.img.jpg%2F1339349457238.jpg&SDK =乔伊
Chrome返回的网址包含错误
https://www.facebook.com/dialog/feed?access_token=AAAFd06xhTEYBAANOHKdNqP9q7KudRVNgYqpptGHgkVeXwaRBjqIzOP99O06h40ionI8GugH6ENBkTyAwj6l87Eb3zJZAi1vHNQI0o7gWZC9pfysDk9&api_key=384638688250950&app_id=384638688250950&caption=Amazing%20Journeys%20by%20Malaysia%20Airlines&channel=https%3A%2F%2Fs-static.ak.facebook.com%2Fconnect %2Fxd_arbiter.php%3Fversion%3D8%23CB%3Df1ca796e2c%26origin%3Dhttps%253A%252F%252Fmas-fb.net%252Ff356d6e91%26domain%3Dmas-fb.net%26relation%3Dparent.parent&channel_url = HTTPS%3A%2F%2FS -static.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D8%23CB%3Df1bb0a298c%26origin%3Dhttps%253A%252F%252Fmas-fb.net%252Ff356d6e91%26domain%3Dmas-fb.net%26relation%3Dparent .parent&描述=马来西亚%20Airlines%图20是%20back%20with%20Amazing%20Journeys%20from%20only%20RM272%20from%2011th%20-%第二千〇十八%20June%202012.&显示= IFRAME&链路= HTTP%3A%2F%2Fwww.malaysiaairlines . COM%2Fmy%2Fen%2Fdeals%2Fdeals-的最day.html%3Fcid%3D2145&语言环境= EN_US&名称= MAS%20Amazing%20Journey%20Deals&下一= HTT PS%3A%2F%2Fs-static.ak.facebook.com%2Fconnect%2Fxd_arbiter.php%3Fversion%3D8%23CB%3Df3b274234c%26origin%3Dhttps%253A%252F%252Fmas-fb.net%252Ff356d6e91%26domain%3Dmas- fb.net%26relation%3Dparent%26frame%3Df3ebd35ae%26result%3D%2522xxRESULTTOKENxx%2522&图片= HTTP%3A%2F%2Fwww.malaysiaairlines.com%2Fcontent%2Fmas管理员%2Fmy%2Fen%2Fsite配置%2Fhomepagethreatre%2Fbook% 2FAmazingWorldwideDeals%2F_jcr_content%2Fcontentpar%2Fmasimage_9126.img.jpg%2F1339349457238.jpg&SDK =乔伊