Is there a way to check if user has granted a given permission in server-side?
I need to check if user has granted a given permission (for exam开发者_如何学Cple: publish_stream) in server-side. It seams for client-side exists solution but what I need is for server-side.
Any idea please?
You need a server side API like the Facebook Java API or restFB. These are java APIs (that I have used), there a host of others for different languages. The official ones are shown on the Facebook developer portal.
Using these APIs you will be able to do more than just authenticate a user on the server side. Follow the link to the different pages and you'll find snippets that will get you started in no time!
EDIT
Since you're using ASP, you'll need an ASP .NET API. This is the first result found from a google search http://facebooksdk.codeplex.com/ .
Using this API and an MVC architecture, you are able to annotate any controller actions that contain code that requires permissions with something like [CanvasAuthorize(Perms = "publish_stream")]
and when the user calls that action they'll need to provide permission.
I cant give more details as I've never used this API but do check out this in-depth tutorial on building a sample application.
You can make a Graph API call to this URL https://graph.facebook.com/me/permissions including the user access token. You will get results with the user's permissions. For more details see https://developers.facebook.com/docs/reference/api/user/
Solution:
Step 1. First u must make a query:
query is like: SELECT {0} FROM permissions WHERE uid = {1}
{0} is comma-separated permissions. for example: publish_stream,offline_access
{1} is userId
Step 2. Then send this query to the given url:
url: https://api.facebook.com/method/fql.query?query={0}&format=JSON&access_token={1}
{0} is query that we made in step1
{1} is user's AccessToken
Sample Result: [{"publish_stream":1,"offline_access":0}]
Update Another way with using Graph Api:
https://graph.facebook.com/me/permissions?access_token={0}
{0} is user's AccessToken
Sample Result:
{
"data": [
{
"installed": 1,
"status_update": 1,
"photo_upload": 1,
"video_upload": 1,
"offline_access": 1,
"create_note": 1,
"share_item": 1,
"bookmarked": 1,
"publish_stream": 1
}
] }
精彩评论