我试图吸引用户的Facebook喜欢。如果我单独为每个用户拨打电话,那么呼叫成功,但如果我遍历我的数据库中的用户,则呼叫立即失败。脚本如下。不知道为什么会这样。什么是解决方案?
<?php
$conn = mysql_connect('***', '***', '*****');
mysql_select_db('*****', $conn);
//Application Configurations
$site_url = $webPath . 'index.php';
try {
require_once $behindPath . "src/facebook.php";
} catch (Exception $e) {
error_log($e);
}
// Create our application instance
$facebook = new Facebook(array(
'appId' => $app_id,
'secret' => $app_secret,
));
//$usertoken = $facebook->setAccessToken($access_token);
// Get User ID
try {
$user = $facebook->getUser();
} catch (Exception $e) {
header("Location: error.php?err= Some Error has occured. Please try again Later.");
die();
}
//if($user){
//$accessToken = $facebook->getAccessToken();
//以下是获取喜欢尚未被提取的用户的facebook ID的查询
$query = "SELECT uid, facebook_access_token FROM fbusers WHERE facebook_id IN(SELECT facebook_id FROM user_self WHERE device = 'ios' AND facebook_id NOT IN(SELECT facebook_id FROM user_interest) ORDER BY id DESC)";
$res = mysql_query($query);
$numrows = mysql_num_rows($res);
while ($row = mysql_fetch_array($res)) {
$access_token = $row['facebook_access_token'];
$uid = $row['uid'];
echo $uid . "<br />";
try {
// Proceed knowing you have a logged in user who's authenticated.
$usertoken = $facebook->setAccessToken($access_token); //echo $usertoken; exit;
} catch (FacebookApiException $e) {
error_log($e);
}
/////////////////////////
// Insert Likes
/////////////////////////
// prepare array for insertion
$I = $me = $facebook->api('/me');
$me_v = $facebook->api('/me/movies');
$me_t = $facebook->api('/me/television');
$me_b = $facebook->api('/me/books');
$me_m = $facebook->api('/me/music');
// For movies Likes
foreach ($me_v['data'] as $key => $value) {
//d($value);
$update[] = $I['id'];
$update[] = $value['id'];
$update[] = $value['name'];
$update[] = 'movie';
$insert_intrests->execute($update);
$update = '';
}
// For tv shows Likes
foreach ($me_t['data'] as $key => $value) {
//d($value);
$update[] = $I['id'];
$update[] = $value['id'];
$update[] = $value['name'];
$tv_str = str_replace(" ", "_", 'Tv show');
$update[] = $tv_str;
$insert_intrests->execute($update);
$update = '';
}
// For Books Likes
foreach ($me_b['data'] as $key => $value) {
//d($value);
$update[] = $I['id'];
$update[] = $value['id'];
$update[] = $value['name'];
$update[] = 'book';
$insert_intrests->execute($update);
$update = '';
}
// For music Likes
foreach ($me_m['data'] as $key => $value) {
//d($value);
$update[] = $I['id'];
$update[] = $value['id'];
$update[] = $value['name'];
$update[] = 'music';
$insert_intrests->execute($update);
$update = '';
}
/////////////////////////
// END Insert Likes
/////////////////////////
}
mysql_close($conn);
?>