我有一个脚本会生成 1000089838938 等随机数字,但我需要一个解决方案来检查生成的数字是否与有效的Facebook帐户相关联。
我正在寻找的解决方案应该是PHP。
感谢。
答案 0 :(得分:1)
一种解决方案是在通过Graph API生成后检查ID。
http://graph.facebook.com/[ID]
生成任何ID,将其放在URL的末尾并检查收到的响应。比如ID是1303834107
您可以查看@ http://graph.facebook.com/1303834107
如果它是正确的,响应将是这样的:
{
"id": "1303834107",
"name": "John Flake",
"first_name": "John",
"last_name": "Flake",
"link": "https://www.facebook.com/john.flake",
"username": "john.flake",
"gender": "male",
"locale": "en_US"
}
或者如果该ID无效,您将得到类似的内容:
{
"error":
{
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
根据回复,您可以验证该ID。
使用php curl在生成ID时每次调用API URL以检查响应。
答案 1 :(得分:0)
这很容易:
只需从你的php进行卷曲调用即可:
https://graph.facebook.com/1457691266/
将其替换为任何ID - 1000089838938
如果你得到一个响应的json,那么这个ID是有效的,否则你将得到不支持的get请求。 :)
希望它有所帮助。
答案 2 :(得分:0)
你可以这样做
$url = get_data("https://graph.facebook.com/+".$id."'");
$id = json_decode($url, true);
$id = $id['data'][0]['username'];
$ id为您提供已发布ID的用户名。