我们在 Facebook 上有一个应用程序。即使用户处于离线状态,它也会代表用户每小时发布一次报价。但是当 php 脚本运行以发布到用户时间线时,我实际上面临着 2 个严重的问题。
首先也是最紧迫的是,当您从 BlackBerry、Samsung 和 iphone 等新的触摸手机阅读新闻提要时,用户名下不会显示“通过应用程序名称”。这一点非常关键,因为应用用户不喜欢在没有“通过应用名称”的情况下直接代表他们发布内容。
其次,脚本需要将近 40 秒才能执行,但是到目前为止我只有 15 个用户。请帮忙。这是我的 PHP 代码:
<?PHP
require_once '../inc/config.php';
$dbh = new PDO('mysql:dbname=' . $db_name . ';host=' . $db_host . ';charset=utf8', $db_username, $db_password);
$dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, 1);
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sqlid = "SELECT fb_id FROM offline_access_users";
$sqlmsg = "SELECT msg_id,message FROM fb_messages WHERE msg_id = (SELECT MAX(msg_id) FROM fb_messages WHERE sent = 'No' ORDER BY msg_id)";
try {
$stmt = $dbh->prepare($sqlid);
$stmt->execute();
$msg = $dbh->prepare($sqlmsg);
$msg->execute();
$msg_to = $msg->fetch();
$msg_tosend = $msg_to['message'];
$msg_tosendid = $msg_to['msg_id'];
}
catch (PDOException $e) {
echo $e->getMessage();
die();
}
while ($value = $stmt->fetch()) {
$id = $value['fb_id'];
$url = "https://graph.facebook.com/" . $id . "/feed";
$ch = curl_init();
$attachment = array(
'access_token' => $access_token,
'message' => $msg_tosend,
'app_id' => $fb_app_id,
'from' => $fb_app_id,
'display' => "touch",
'to' => "",
'redirect_uri' => "http://mydomain.com",
'link' => "",
'picture' => "",
'source' => "",
'caption' => "",
'description' => "",
'actions' => ""
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FRESH_CONNECT, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $attachment);
$result = curl_exec($ch);
}
curl_close($ch);
$sqlupdate = "UPDATE fb_messages SET sent = 'Yes' WHERE msg_id=" . $msg_tosendid;
try {
$stmt = $dbh->prepare($sqlupdate);
$stmt->execute();
}
catch (PDOException $e) {
echo $e->getMessage();
die();
}
$db = null;
?>