php Facebook OAuthException:“用户尚未授权应用程序执行此操作”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4158164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook OAuthException: "user hasn't authorized the application to perform this action"
提问by Mohammad Emran Hasan
Using the Facebook PHP SDK, I'm getting the following error when I try to post a status update:
使用 Facebook PHP SDK,当我尝试发布状态更新时出现以下错误:
Fatal error: Uncaught OAuthException: (#200) The user hasn't authorized the application to perform this action
致命错误:未捕获的 OAuthException:(#200)用户尚未授权应用程序执行此操作
These are the steps I've taken:
这些是我采取的步骤:
Get code:
https://graph.facebook.com/oauth/authorize?client_id=FB_APP_ID&redirect_uri=REDIRECT_URI
Get access token:
https://graph.facebook.com/oauth/access_token?client_id=FB_APP_ID&code=CODE&client_secret= FB_SECRET&redirect_uri=REDIRECT_URI
Attempt the status update:
require_once(facebook.php); $fb = new Facebook(array( 'appId' => FB_APP_ID, 'secret' => FB_SECRET )); $post = $fb->api('me/feed', 'POST', array( 'access_token' => ACCESS_TOKEN, 'message' => 'hello world!' ));
获取代码:
https://graph.facebook.com/oauth/authorize?client_id=FB_APP_ID&redirect_uri=REDIRECT_URI
获取访问令牌:
https://graph.facebook.com/oauth/access_token?client_id=FB_APP_ID&code=CODE&client_secret= FB_SECRET&redirect_uri=REDIRECT_URI
尝试状态更新:
require_once(facebook.php); $fb = new Facebook(array( 'appId' => FB_APP_ID, 'secret' => FB_SECRET )); $post = $fb->api('me/feed', 'POST', array( 'access_token' => ACCESS_TOKEN, 'message' => 'hello world!' ));
I don't see any settings in my application that would authorize the application to do this, but maybe I'm missing something. Any suggestions?
我在我的应用程序中没有看到任何可以授权应用程序执行此操作的设置,但也许我遗漏了一些东西。有什么建议?
回答by Mohammad Emran Hasan
Make sure you ask for extended publish_stream
permission when you're requesting code (added as the third parameter):
确保publish_stream
在请求代码时请求扩展权限(添加为第三个参数):
https://graph.facebook.com/oauth/authorize?client_id=' . FB_APP_ID . '&redirect_uri=' . REDIRECT_URI . '&scope=publish_stream'
Hope this helps.
希望这可以帮助。
Cheers!
干杯!
回答by Richard Merchant
I had the same problem and this post really helped me out http://facebook.stackoverflow.com/a/8502709/965536
我遇到了同样的问题,这篇文章真的帮助了我http://facebook.stackoverflow.com/a/8502709/965536
The only difference with my problem was that I was using the PHP SDK but essentially it works the same. I used the api call
与我的问题的唯一区别是我使用的是 PHP SDK,但本质上它的工作原理相同。我使用了 api 调用
$permissions = $facebook->api('/me/permissions');
You can then run your checks
然后你可以运行你的检查
if(isset($permissions['data'][0]['publish_stream']) && $permissions['data'][0]['publish_stream'])
This works for me but someone may have a better answer. Also you should wrap your publish post stream in a try catch
这对我有用,但有人可能有更好的答案。此外,您应该将发布帖子流包装在 try catch 中
Hope this helps.
希望这可以帮助。
Thanks
谢谢
回答by datnt
I put here some more information:
我在这里放了一些更多的信息:
Mark's replied above has lead me to the right direction. But it took me another 5 hours to figure out the solution.
马克上面的回答引导我走向正确的方向。但是我又花了 5 个小时才找到解决方案。
- I'm using omniauth-facebook for ruby on rails.
- I need to set the scope for omniauth (Please refer to https://github.com/mkdynamic/omniauth-facebook)
- I also ready this post from "Lu Chen" to set the right scope request http://developers.facebook.com/blog/post/2012/04/25/streamlining-publish_stream-and-publish_actions-permissions/
- 我正在将 omniauth-facebook 用于 ruby on rails。
- 我需要设置 omniauth 的范围(请参考https://github.com/mkdynamic/omniauth-facebook)
- 我还准备了“陆晨”的这篇文章来设置正确的范围请求 http://developers.facebook.com/blog/post/2012/04/25/streamlining-publish_stream-and-publish_actions-permissions/
So, here is the result for omniauth.rb:
所以,这是 omniauth.rb 的结果:
provider :facebook, ENV['FACEBOOK_KEY'], ENV['FACEBOOK_SECRET'],
:scope => 'email,user_birthday,publish_actions'
回答by Anthony Corbelli
Have you taken the other steps required to connect the user with your app and get them to authorize your app to perform these actions? You need to register the users then call showPermissionDialog to let them log in and authorize your app. That's what this error is telling you.
您是否采取了将用户与您的应用联系起来并让他们授权您的应用执行这些操作所需的其他步骤?您需要注册用户,然后调用 showPermissionDialog 让他们登录并授权您的应用程序。这就是这个错误告诉你的。