【问题标题】:Facebook api 5V get emailFacebook api 5V 获取电子邮件
【发布时间】:2017-03-15 16:19:06
【问题描述】:

我在使用 php 从 Facebook sdk 获取电子邮件地址时遇到问题。

错误信息:

注意:未定义的变量:请求在 /storage/h5/727/1013727/public_html/index.php 在第 94 行

致命错误:未捕获的错误:调用成员函数 execute() on /storage/h5/727/1013727/public_html/index.php:94 中的 null 堆栈跟踪:

0 {main} 在 /storage/h5/727/1013727/public_html/index.php 中抛出 第 94 行

我的代码是:

    <?php
  /* PHP SDK v5.0.0 */
/* make the API call */
$request = new FacebookRequest(
  $session,
  'GET',
  '/{email}'
);
$response = $request->execute();
$graphObject = $response->getGraphObject();
/* handle the result */
    ?>

我唯一需要的是:

require_once __DIR__ . '/facebook-sdk-v5/autoload.php';

我应该制作一个加载所有内容的 config.php 吗?如果是这样,你知道 git 上有什么东西,因为我找不到 (V5)

【问题讨论】:

  • 用file_exists函数检查文件是否存在

标签: php html facebook-graph-api facebook-php-sdk


【解决方案1】:

来自官方Facebook PHP SDK documentation,你应该这样做:

$fb = new \Facebook\Facebook([
  'app_id' => '{app-id}',
  'app_secret' => '{app-secret}',
  'default_graph_version' => 'v2.8',
  //'default_access_token' => '{access-token}', // optional
]);

$response = $fb->get('/{user-id}?fields=email', '{access-token}');

$user = $response->getGraphUser();

【讨论】:

  • 我收到此错误:致命错误:未捕获 Facebook\Exceptions\FacebookAuthenticationException: (#803) 您请求的某些别名不存在:电子邮件在 ....
  • 该错误是因为/email 中的email 不是有效的API 调用。您需要致电/{user-id}。见developers.facebook.com/tools/explorer/145634995501895/…
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-04-06
  • 1970-01-01
  • 2015-11-07
  • 1970-01-01
  • 2011-11-11
  • 1970-01-01
相关资源
最近更新 更多