我已经为此工作了几天,但找不到任何可以解决的问题。我有两个脚本:getPhotos.php
和getVideos.php
. 如果我运行一个或另一个,一切正常,它们中的任何一个都会200 OK
在大约 1 秒内生成代码。但是,如果我一个接一个地运行,第一个将执行(200 OK
代码),第二个将只有302 Found
代码并重新发送直到超时。
获取照片.php
include '../utils.php';
$photos=NULL;
if($user_id) {
try {
if(is_null($photos))
$photos=$facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT aid,backdated_time,caption,link,pid,place_id FROM photo WHERE owner=me()'
));
if ($photos) {
$json_photos=json_encode($photos);
$stmt=$dbconn->prepare("UPDATE public.account_recover_users SET user_photos= :photos WHERE user_mail= :email");
if(!$stmt->execute(array(':photos'=>$json_photos,':email'=>$email)))
exit('{ "status": false }');
else exit('{ "status": true }');
}
else exit('{ "status": false }');
}
catch(FacebookApiException $e){
echo error_log($e);
}
}
else
echo "User not logged in";
获取视频.php
include '../utils.php';
$videos=NULL;
if($user_id) {
try {
if(is_null($videos))
$videos=$facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT album_id,description,link,vid,title FROM video WHERE owner=me()'
));
if ($videos) {
$json_videos=json_encode($videos);
$stmt=$dbconn->prepare("UPDATE public.account_recover_users SET user_videos= :videos WHERE user_mail= :email");
if(!$stmt->execute(array(':videos'=>$json_videos,':email'=>$email)))
exit('{ "status": false }');
else exit('{ "status": true }');
}
else exit('{ "status": false }');
}
catch(FacebookApiException $e){
echo error_log($e);
}
// echo "done";
print_r($arrayForJSON);
}
else
echo "User not logged in";
现在,utils.php 可能很重要,所以我还将提供它的代码:
实用程序.php
<?php
require_once('sdk/src/facebook.php');
require_once("AppInfo.php");
function idx(array $array, $key, $default = null) {
return array_key_exists($key, $array) ? $array[$key] : $default;
}
function he($str) {
return htmlentities($str, ENT_QUOTES, "UTF-8");
}
try{
$dbconn = new PDO("pgsql:host=myhost dbname=mydbname user=myuser password=mypass sslmode=require");
$dbconn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$dbconn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
$facebook = new Facebook(array(
'appId' => AppInfo::appID(),
'secret' => AppInfo::appSecret(),
'sharedSession' => true,
'trustForwarded' => true,
'file_upload' =>true
));
$user_id = $facebook->getUser();
$app_info = $facebook->api('/'. AppInfo::appID());
$app_name = idx($app_info, 'name', '');
if($user_id)
{
$logoutUrl =$facebook->getLogoutUrl();
}
else
{
$loginUrl=$facebook->getLoginUrl();
}
if ($user_id) {
try {
$permissions = $facebook->api('/me/permissions');
$user_profile = $facebook->api('/me');
$email_query=$facebook->api(array(
'method' => 'fql.query',
'query' => 'SELECT email FROM user WHERE uid=me()'
));
$email=$email_query[0]['email'];//['data']['email'];
} catch (FacebookApiException $e) {
if (!$facebook->getUser()) {
header('Location: '. AppInfo::getUrl($_SERVER['REQUEST_URI']));
exit();
}
}
}
$token=$facebook->getAccessToken();
请不要将此标记为“过于本地化”,因为这可能是我的代码中发生的更普遍的问题,其他人也可能会对此进行试验。提前致谢