authentication document中明确说明:
应用取消授权
当您的应用的用户在
应用程序仪表板或阻止应用程序
新闻提要,您的应用程序可以
通过指定取消授权通知
开发者应用中的回调 URL。
在应用程序删除期间,我们将发送
HTTP POST 请求包含一个
参数,signed_request,其中
包含用户的用户 ID (UID)
刚刚删除了您的应用程序。你会
未收到用户访问令牌
此请求和所有现有用户
访问令牌将自动
过期了。
所以在自己的文档中使用signed_request 函数:
<?php
function parse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode('.', $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
error_log('Unknown algorithm. Expected HMAC-SHA256');
return null;
}
// check sig
$expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log('Bad Signed JSON signature!');
return null;
}
return $data;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, '-_', '+/'));
}
$result = parse_signed_request($_REQUEST['signed_request'],"APP_SECRET");
$myFile = "deauthorize.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
fwrite($fh, $result["user_id"] . "\n");
fclose($fh);
?>
所以您需要做的就是获取$result["user_id"] 查询您的数据库并删除记录。
P.S:我建议添加一个名为 active 的新字段,然后停用用户而不是一起删除记录。
编辑:
Facebook 不会将用户重定向到取消授权的 URL!它只会 ping 它:
Facebook 在用户 ping 此 URL 时
取消对您的应用的授权