通过应用程序向FB用户发送通知 [英] Send FB user a notification via App

查看:114
本文介绍了通过应用程序向FB用户发送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过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 //访问令牌被安全删除。 

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给我一个错误消息:



pre> {error:{message:需要用户访问令牌来请求此资源,type:OAuthException,code:102 }}


解决方案

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


I'm getting an App access token via the Facebook API.

$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);

When $app_token is echoed, the following is displayed

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

The "ID" is equal to my application ID (which I'm not silly enough to write). There's a vertical bar that separates the ID from another alphanumeric string.

I'm not very experienced with this aspect of the API, particularly doing what involves App access token rather than user access tokens.

So, when I tried to send a test notification in a php script

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

$result gives me an error message as such:

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

解决方案

As indicated on https://developers.facebook.com/docs/concepts/notifications/, you should using HTTP POST requests to send notification to the user of your apps, not HTTP GET requests.

这篇关于通过应用程序向FB用户发送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆