如何验证 Facebook 应用 ID

发布于 2024-11-19 13:59:38 字数 136 浏览 0 评论 0原文

我需要检查给定的 Facebook 应用程序 ID 是否有效。另外,我需要检查为此应用程序 ID 设置了哪些域和站点配置。它是通过 PHP 还是 Javascript 完成并不重要。

我查遍了所有地方,但找不到任何有关此的信息。有什么想法吗?

I need to check if the given Facebook app id is valid. Also, I need to check which domain and site configurations are set for this app id. It doesn't matter if it's done through PHP or Javascript.

I checked everywhere but couldn't find any information about this. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

指尖凝香 2024-11-26 13:59:38

您可以通过访问 http://graph.facebook.com/ 并查看它是否加载您期望的内容来验证 ID。有关应用程序信息,请尝试使用 admin.getAppProperties,使用属性 从此列表

You can validate the ID by going to http://graph.facebook.com/<APP_ID> and seeing if it loads what you expect. For the app information, try using admin.getAppProperties, using properties from this list.

三生殊途 2024-11-26 13:59:38

使用图形 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 属性并检查它是否为 application。如果根本没有找到 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');
}
?>

Use the Graph API. Simply request:

https://graph.facebook.com/<appid>

It should return you a JSON object that looks like this:

{
  id: "<appid>",
  name: "<appname>",
  category: "<app category>",
  subcategory: "<app subcategory>",
  link: "<applink>",
  type: "application",
}

So, to validate if the specified app_id is indeed the id of an application, look for the type property and check if it says application. If the id is not found at all, it will just return false.

More info: https://developers.facebook.com/docs/reference/api/application/

For example:

<?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');
}
?>
吐个泡泡 2024-11-26 13:59:38

使用 Graph 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 . . .

更多信息:适用于 PHP 的 Facebook SDK 的 FacebookResponse

Use the Graph 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 . . .

More info:FacebookResponse for the Facebook SDK for PHP

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文