我尝试按照示例操作:https://github.com/facebook/php-graph-sdk但是当我在浏览器中运行时http://192.168.33.10/fb_api/firstapp.php/,错误:图表返回错误:API参数中提供的appsecret_proof无效。我检查了app_id和app_scret。 我的源代码:
<!DOCTYPE html>
<html>
<head>
<title>First App</title>
<meta charset="utf-8">
</head>
<body>
<?php
$access_token = 'EAACEdEose0cBABaxt3VjDmUiG8H5DQ8Dhju....';
$app_secret = '98680d3e6a251b52d87d...';
$appsecret_proof= hash_hmac('sha256', $access_token, $app_secret);
require "phpsdk/src/Facebook/autoload.php";
$fb = new Facebook\Facebook([
"app_id" => '11651982...',
"app_secret" => '98680d3e6a251b52d87...',
'default_graph_version' => 'v2.10',
]);
try {
// Get the \Facebook\GraphNodes\GraphUser object for the current user.
// If you provided a 'default_access_token', the '{access-token}' is optional.
$response = $fb->get('/me', 'EAACEdEose0cBABaxt3VjDmUiG8H5DQ8DhjuZB12Phbyc2ZB0G....');
} 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;
}
$me = $response->getGraphUser();
echo 'Logged in as ' . $me->getName();
?>
</body>
</html>