简体   繁体   English

应用发布通知给用户。 如何获得应用程序的访问令牌?

[英]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.

相关问题 Facebook App Uncaught OAuthException:必须使用活动访问令牌来查询有关当前用户的信息。 抛出 - Facebook App Uncaught OAuthException: An active access token must be used to query information about the current user. thrown 如何获取应用程序的访问令牌,以便可以将页面发布为页面? - How can I get the access token of my app so I can post on a page as a page? 我如何从Facebook上带有访问令牌的帖子中获取评论 - how do i get the comments from a post in facebook with an access token 如何通过Facebook PHP SDK获取App Access Token? - How do I get the App Access Token via the Facebook PHP SDK? 当我尝试获取使用帖子用户访问令牌由我的应用创建的帖子数据时,Facebook graph API返回“不支持的获取请求” - Facebook graph api returns “Unsupported get request” when I try to get a post data created by my app using the post user access token 如何在不进行应用审查的情况下获取状态访问令牌? 如果我托管在我的网站上,仍然需要对用户状态数据进行应用审查? - How to get status access token without app review ? If i host on my website still i need to give app review for user status data ? 如何访问用户在Facebook应用中发布的留言墙 - How do I access wall posts made by the user in a facebook app 从应用程序获取具有Facebook访问令牌的用户供稿 - Get user feed with Facebook access token from app 在 laravel 护照客户端应用程序中使用访问令牌获取用户数据 - Get user data using access token in laravel passport client app 使用javascript SDK和应用访问令牌获取Facebook用户名 - Get Facebook user name with javascript SDK and app access token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM