Authentication to display my Wall on my website

一笑奈何 提交于 2019-12-08 10:45:32

问题


I'm trying to get a JSON object of my Facebook wall posts to display on my website but it seems to be ridiculously complicated for such a simple task.

Do I need to implement server-side redirects and then post data back 'pretending' to be a user just so that I can get a token or am I misunderstanding something here?!

How can I request the JSON object of my Wall Stream given the fact that I have an API key & secret etc? Currently I can't work out how to turn these details into a proper access_token that can actually be used with FacebookClient.Get("Me", parameters).

I've read somewhere that I can get an infinite session key that will never expire but following the steps given here simply cause an error at the 2nd step.

I have read loads of documentation and tried to find examples but almost everything I've found starts after authentication.

Any help is much appreciated.


回答1:


First, you need to get an access token (there is no getting around this). This is done via an OAuth Dialog where the user signs-in and provides the required permission. You will have to request the "offline_access" and "read_stream" permissions to do what you are trying to. Getting the access_token is pretty simple. Follow the instruction here: http://osnapz.wordpress.com/2010/04/23/using-asp-net-with-facebooks-graph-api-and-oauth-2-0-authentication/

Also, read up Facebook's documentation: http://developers.facebook.com/docs/authentication/

You will have to store your access token somewhere for later use (this is the infinite session key)

After you get the access token, you can call the graph API directly:

https://graph.facebook.com/me/feed/?access_token=YOUR-TOKEN-HERE

OR you can use the Facebook C# SDK (recommended).

FYI, the link you posted is out-dated and Facebook will not support that method soon.

UPDATE - MANUAL WAY OF GETTING AN ACCESS TOKEN:

Since you are only interested in your data, so you will only have to get the access token ONCE. Of course, you will have to do this again if you change your password.

I will detail a manual way of getting your token.

  1. Make sure you are using Firefox. It actually displays JSON strings.
  2. Navigate to this URL. Add your App ID, callback-url (this should match the domain you in your registration). I have added a lot of permissions.

https://www.facebook.com/dialog/oauth?display=popup&client_id=YOUR-APP-ID&redirect_uri=YOUR-CALLBACK-URL&scope=offline_access,read_stream,email,read_insights,user_events,user_groups,user_interests,user_likes,user_location,user_notes,user_photo_video_tags,user_photos,user_relationships,user_religion_politics,user_status,user_videos,user_website,user_work_history,read_friendlists,read_requests,friends_likes,friends_location,friends_notes,friends_photo_video_tags,friends_photos,friends_relationships,friends_religion_politics,friends_status,friends_videos,friends_website,friends_work_history,user_checkins,friends_checkins

  1. Once you authenticate and "Allow", Facebook will redirect to your callback URL is a "code" parameter. Make a note of this parameter.

  2. Now call another URL, add your app id, api secret, and the code.

https://graph.facebook.com/oauth/access_token?client_id=YOUR-APP-ID&redirect_uri=YOUR-CALLBACK-URL&client_secret=API-SECRET&code=CODE-YOUR-COPIED-BEFORE

  1. Calling the URL above will display the access token in the browser. Save this access token. Now you can use this token to make API calls on your behalf.

  2. Remember, you will have go through this process again if you change your password.

This is a manual way and only intended in your scenario where you are only interested in your data. I do this for testing purposes.



来源:https://stackoverflow.com/questions/6202397/authentication-to-display-my-wall-on-my-website

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!