[英]App post notification to user. How do I get an access token for app?
I am using the new version 2, sdk 4.0 php. 我正在使用新版本2,sdk 4.0 php。 I am trying to send a notification to a user with my app. 我正在尝试通过我的应用向用户发送通知。 I just realised the access token that I get via login (user access token) is different to the access token for my app. 我刚刚意识到通过登录获取的访问令牌(用户访问令牌)与我的应用程序的访问令牌不同。 I have searched online before posting it on here, but most is for the old sdk and cannot get the right syntax to work with mine. 在将其发布到这里之前,我已经在网上搜索过,但是大多数都是针对旧的sdk的,无法获得与我的语法兼容的语法。
My code: 我的代码:
$notification = (new FacebookRequest(
$session,
'POST',
'/'.$id[0].'/notifications',
array (
'href' => "http://localhost/app/index.php",
'template' => 'You have been tagged, please set privacy preference',
)
))->execute()->getGraphObject()->asArray();
And my error: 我的错误:
Fatal error: Uncaught exception 'Facebook\\FacebookAuthorizationException' with message '(#15) This method must be called with an app access_token.' 致命错误:消息为(#15)的未捕获异常'Facebook \\ FacebookAuthorizationException',必须使用应用程序access_token调用此方法。 in C:\\xampp\\htdocs\\app\\Facebook\\FacebookRequestException.php:134 Stack trace: #0 C:\\xampp\\htdocs\\app\\Facebook\\FacebookRequest.php(268): Facebook\\FacebookRequestException::create('{"error":{"mess...', Object(stdClass), 400) #1 C:\\xampp\\htdocs\\app\\privacy.php(121): Facebook\\FacebookRequest->execute() #2 {main} thrown in C:\\xampp\\htdocs\\app\\Facebook\\FacebookRequestException.php on line 134 在C:\\ xampp \\ htdocs \\ app \\ Facebook \\ FacebookRequestException.php:134堆栈跟踪中:#0 C:\\ xampp \\ htdocs \\ app \\ Facebook \\ FacebookRequest.php(268):Facebook \\ FacebookRequestException :: create('{“错误“:{” mess ...',Object(stdClass),400)#1 C:\\ xampp \\ htdocs \\ app \\ privacy.php(121):Facebook \\ FacebookRequest-> execute()#2 {main}抛出在第134行的C:\\ xampp \\ htdocs \\ app \\ Facebook \\ FacebookRequestException.php中
Can someone help me with getting the app access token? 有人可以帮助我获取应用访问令牌吗?
You can get the app access_token as follows: 您可以按以下方式获取应用程序access_token:
$appSession = FacebookSession::newAppSession();
Then you can do: 然后,您可以执行以下操作:
$notification = (new FacebookRequest(
$appSession,
'POST',
'/'.$id[0].'/notifications',
array (
'href' => "http://localhost/app/index.php",
'template' => 'You have been tagged, please set privacy preference',
)
))->execute()->getGraphObject()->asArray();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.