I'm trying to understand how the facebook api works. The end goal is to be able to read the posts from a facebook page.
If someone has connected with my app on facebook can my c# application then get the posts from a public facebook page if it knows their facebook account id (and has the facebook app secret hard coded).
If so what are the http requests it needs to make in order to get the access token which can then be used to get the posts, and what are the requests to get a new access token before one expires?
If you could provide an example in c# (maybe using the acebooksdk.net library) that would be great!
Thanks.
Now expand the Setting menu and select Basic. Here you can find the App ID and App Secret. Then click on the “Show” button in the “App Secret” text box. You can copy the “App Id” and “App Secret” which you can use for your Facebook API calls.
At a high level, you obtain a long-lived token for the client by: Using a valid, long-lived access token, your server sends a request to get a code from Facebook. Facebook sends a code back to your server and you securely send this code to the client.
The way to do it was using "The Login Flow for Web (without JavaScript SDK)" api to get a user access token. A user access token is required to be sent with graph api queries in order to get page posts.
The first step is to create an app on facebook where you specify what information you want the program to be able to access via the graph api. The end user will then choose to accept these permissions later.
The program creates a web browser frame and navigates to https://www.facebook.com/dialog/oauth?client_id={app-id}&redirect_uri=https://www.facebook.com/connect/login_success.html&response_type=token
The response type "token" means that when the (embedded) web browser is redirected to the redirect_uri
the user access token will be added to the end of the url as a fragment. E.g the browser would end up on the page with url https://www.facebook.com/connect/login_success.html#access_token=ACCESS_TOKEN...
The redirect uri can be anything but facebook has that specific one set aside for this scenario where you are not hosting another server which you want to receive and process the response.
Basically facebook gathers all the information required from the user and then sends them to the redirect_uri
. Some information they may require is for them to login and accept permissions your app on facebook requires.
So the program simply keeps an eye on what url the embedded browser is on and when it matches the redirect_uri
it parses the url which will contain the data as fragments and can then close the browser.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With