我已经制作了一个完美运行的 Facebook 应用程序,所以现在我正在尝试设置一个移动应用程序。我使用文档中描述的此代码来检查用户是否已登录,如果用户已登录,则将信息转发。
这是我正在使用的代码:
<?php
session_start();
// Include facebook PHP SDK
require_once("lib/facebook.php");
// Configure the facebook object
$config = array();
$config['appId'] = 'APP_ID';
$config['secret'] = 'APP_SECRET';
$config['cookie'] = true;
$config['fileUpload'] = true;
$app_id = 'APP_ID';
$canvas_page = "https://hadadmin.yourwebhosting.com/mixit/mobile/";
$location = "https://www.facebook.com/dialog/oauth?client_id="
. $app_id . "&redirect_uri=" . urlencode($canvas_page) . "&scope=publish_stream,email,create_event,rsvp_event,user_events,friends_events";
// initialize the facebook oject
$facebook = new Facebook($config);
// Get Facebook User
$fbID = $facebook->getUser();
// Get the current access token
$access_token = $facebook->getAccessToken();
// check if we have valid user
if ($fbID) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$fb_user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
$fbID = NULL;
// seems we don't have enough permissions
// we use javascript to redirect user instead of header() due to Facebook bug
print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';
// kill the code so nothing else will happen before user gives us permissions
die();
}
} else {
// seems our user hasn't logged in, redirect him to a FB login page
print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';
// kill the code so nothing else will happen before user gives us permissions
die();
}
我已经搜索过所有类似问题的解决方案都没有工作(即getUser返回0)getUser返回0就像在其他帖子中一样,但就像我说的那样,当我不使用移动网站时它工作正常,应用程序.facebook.com/MYAPP 和https://hadadmin.yourwebhosting.com/mixit/也在工作。