我有以下代码。每次我加载此页面时,如果没有 user_id 信息,则需要 3-5 秒。我可以减少时间以使其加载更快吗?
$user_id = $facebook->getUser();
if ($user_id) {
echo "have user";
try {
$user_profile = $facebook->api('/me','GET');
} catch (FacebookApiException $e) {
error_log($e);
$user_id = null;
}
$_SESSION['facebook']= $_SESSION;
$_SESSION['user_profile'] = $user_profile;
} else {
echo "no user";
$loginUrl = $facebook->getLoginUrl(
array(
'scope' => 'publish_stream, user_likes'
)
);
echo "<script type='text/javascript'>top.location.href = '$loginUrl'; </script>";
}
我还有以下代码可以将图像发布到用户相册。在它回显“成功”之前大约需要 4-8 秒。有什么办法让它更快?
//Session start
$user_profile = $_SESSION['user_profile'];
$user_id = $user_profile['id'];
// Do the wall post.
$msg_new = "hello";
$link = "XXXXYYYY";
$facebook->setFileUploadSupport(true);
$imgURL = "user_img/".$user_id.".jpg";
$args = array('message' => $msg_new.$link);
$args['image'] = '@' . realpath($imgURL);
$facebook->api('/me/photos', 'post', $args);
$result = "success";
echo $result;
仅供参考:我正在本地主机上测试这个。