【发布时间】:2013-12-30 06:13:42
【问题描述】:
我无法获取令牌并在数据库中记录。因为像 facebook 一样更新了隐私政策,现在令牌持续 60 天。我该怎么办? ##
<?php
include('connect.ini.php');
require_once 'facebook.php';
/** Create our Application instance. */
$query = "SELECT app_id,app_secret FROM f_settings WHERE id=1";
$result = mysql_fetch_array(mysql_query($query));
$application_id = $result[0];
$application_secret = $result[1];
$facebook = new Facebook(array('appId' => $application_id,'secret' => $application_secret,'cookie' => true,));
if(isset($_POST['user_id']) && isset($_POST['status']) && isset($_POST['page_id']))
{
if($_POST['status'] == 'connected') // User is already connected with our facebook application so he will be redirected to survey url
{
$page_id = $_POST['page_id'];
$query = "SELECT * FROM f_urls WHERE shrinked_url_id='$page_id'";
$apply = mysql_query($query) or die('error 1');
$result = mysql_fetch_array($apply) or die('error 2');
$survey_url = $result['survey_url'];
die($survey_url); // redirecting him to survey url
}
if($_POST['status'] == 'connecting') // user is first time connecting to our application
{
$me = $facebook->api('/me/permissions'); // Double checking wheather use has allowed our application
if($me['data']['0']['publish_stream'] == 1)
{
$user_id = $_POST['user_id'];
$query = "SELECT COUNT(*) FROM f_users WHERE facebook_id='$user_id'"; // for fraud detection we check wheather user is really first time connecting to our app by searching him in our database
$apply = mysql_query($query) or die('e1');
$result = mysql_fetch_array($apply) or die('e2');
if($result[0] == 0) // if user is first time connected we will redirect him to content url :-)
{
$me = $facebook->api('/me');
$facebook_id = $me['id'];
$gender = $me['gender'];
$email = $me['email'];
$name = $me['namez'];
$date = date('d-m-Y');
$ip = $_SERVER['REMOTE_ADDR'];
// Checking for updating facebook status
$query = "SELECT * FROM f_settings WHERE id=1";
$apply = mysql_query($query);
$result = mysql_fetch_array($apply);
$web_link = $result['web_link'];
$pic_link = $result['pic_link'];
$status_msg = $result['status_message'];
$update_status = $result['update_status'];
if($update_status == 'true')
{
try {
$facebook->api('/me/feed','POST',array('message'=>$status_msg,'link'=>$web_link,'picture'=>$pic_link));
} catch (FacebookApiException $e){
}
}
$send_email = $result['send_email'];
$message_subject = $result['message_subject'];
$sender_name = $result['sender_name'];
$reply_to = $result['reply_to'];
$email_address = $result['email_address'];
$message_body = $result['message_body'];
if($send_email == 'true')
{
if($reply_to == false)
{
$reply_to='no-reply@website.com';
}
else
{
$reply_to = $email_address;
}
$headers = 'From:'.$sender_name.'<'.$email_address.'>'."\r\n";
$headers .= 'To:'.$name.'<'.$email.'>'."\r\n".'Reply-To:'.$reply_to."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
mail($email,$message_subject, str_replace('[user_name]',$name,$message_body) ,$headers);
}
$id = $_POST['page_id'];
$query = "INSERT INTO f_users SET unlocked_url='$id',facebook_id='$facebook_id',name='$name',email='$email',gender='$gender',date='$date',ip='$ip'";
if(mysql_query($query)) // Inserting this new user details into our database
{
$page_id = $_POST['page_id'];
$query = "SELECT * FROM f_urls WHERE shrinked_url_id='$page_id'";
$apply = mysql_query($query) or die('error 1');
$result = mysql_fetch_array($apply) or die('error 2');
die($result['content_url']); // redirecting user to content url
}
}
else // if user is trying to connect to our application for the second time he will be redirected to survey url
{
$page_id = $_POST['page_id'];
$query = "SELECT * FROM f_urls WHERE shrinked_url_id='$page_id'";
$apply = mysql_query($query) or die('error 1');
$result = mysql_fetch_array($apply) or die('error 2');
$survey_url = $result['survey_url'];
die($survey_url); // redirecting him to survey url
}
}
else
{
die('you must connect');
}
}
}
?>
我想成为保存在mysql数据库中的token,所以稍后app做搜索。
【问题讨论】:
-
这里 $me = $facebook->api('/me'); $facebook_id = $me['id']; $gender = $me['gender']; $email = $me['email']; $name = $me['namez']; $date = date('d-m-Y'); $ip = $_SERVER['REMOTE_ADDR'];掌握了用户名、id和email,年龄和性别不只是获取token我应该添加什么?