通过App向FB用户发送通知

时间:2013-03-30 19:30:49

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

我通过Facebook API获取了App访问令牌。

$app_id = "ID";
$app_secret = "SECRET";
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=".$app_id."&client_secret=".$app_secret."&grant_type=client_credentials";
$app_token = file_get_contents($token_url);

当回显$ app_token时,会显示以下内容

access_token=xxxxxxxxxxxxxxxxxxxxxxxx // access token x'ed out for security.

“ID”等于我的应用程序ID(我写的不够傻)。有一个垂直条,用于将ID与另一个字母数字字符串分开。

我对API的这方面不太熟悉,特别是涉及App访问令牌而不是用户访问令牌。

所以,当我尝试在php脚本中发送测试通知时

$url = "https://graph.facebook.com/".$fb_user_id."/notifications?href=".$url."&".$app_token;
$result = file_get_contents($url);

$ result给出了一条错误信息:

{"error":{"message":"A user access token is required to request this resource.","type":"OAuthException","code":102}}

1 个答案:

答案 0 :(得分:2)

https://developers.facebook.com/docs/concepts/notifications/所示,您应该使用HTTP POST请求向您的应用用户发送通知,而不是HTTP GET请求。