我需要检查给定的Facebook应用ID是否有效。另外,我需要检查为此应用ID设置的域和站点配置。无论是通过PHP还是Javascript完成都没关系。
我到处检查过,但找不到任何相关信息。有什么想法吗?
答案 0 :(得分:9)
您可以转到http://graph.facebook.com/<APP_ID>
并查看是否加载了您的预期来验证ID。有关应用信息,请尝试使用admin.getAppProperties,使用属性from this list。
答案 1 :(得分:4)
使用Graph API。只需要求:
https://graph.facebook.com/<appid>
它应该返回一个如下所示的JSON对象:
{
id: "<appid>",
name: "<appname>",
category: "<app category>",
subcategory: "<app subcategory>",
link: "<applink>",
type: "application",
}
因此,要验证指定的app_id是否确实是应用程序的id,请查找type属性并检查它是否显示应用程序。如果根本找不到id,它将返回false。
更多信息:https://developers.facebook.com/docs/reference/api/application/
例如:
<?php
$app_id = 246554168145;
$object = json_decode(file_get_contents('https://graph.facebook.com/'.$app_id));
// the object is supposed to have a type property (according to the FB docs)
// but doesn't, so checking on the link as well. If that gets fixed
// then check on isset($object->type) && $object->type == 'application'
if ($object && isset($object->link) && strstr($object->link, 'http://www.facebook.com/apps/application.php')) {
print "The name of this app is: {$object->name}";
} else {
throw new InvalidArgumentException('This is not the id of an application');
}
?>
答案 2 :(得分:0)
使用图谱API:
$fb = new Facebook\Facebook(/* . . . */);
// Send the request to Graph
try {
$response = $fb->get('/me');
} catch(Facebook\Exceptions\FacebookResponseException $e) {
// When Graph returns an error
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
// When validation fails or other local issues
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
var_dump($response);
// class Facebook\FacebookResponse . . .