Wednesday, September 18, 2013

Access to Facebook With C#

In the next time I want to post about how to access Facebook with C#. In contrast to the previous WhatsApp posts this connection is explicitely desired by Facebook, which is the reason why the documentation for and support of developers by Facebook is really excellent and highly recommended to read.

At the moment I have two posts in mind which will hopefully go online though, enjoy them. Now a short theoretical introduction, before I continue with the code in the next posts. Facebook offers many APIs for developers. For now we will use the simply but still powerful Graph API. Again here the advice, the documentation is very good and easy to understand, take a look at the link and maybe at the video.

The Graph API is an API which sends requests and commands via HTTP to Facebook, which means that we can access it very easy with HTTP Requests in C#.
The data of facebook are organized as a graph, there is the Graph Explorer with which these can be traversed. I want to present this shortly, since the implementation in C# is an exact copy of these graph actions.

In the Graph Explorer requests can be asked (GET) and changes be induced (POST).
All dates are nodes in the graph, as also the own account. Its ID is written by default in the input line, the request "123456789fields=id,name" then says, that the fields id and name of the node described by 123456789 (which is here the id) should be requested.
Only with this input line much can be done.

But important is also the term access token. This describes rights of single applications (apps). For the previous request we implicitely used the application Graph Explorer. But also own applications can be created, which can be done by the button "Create New App" in the app section of the development page.
Back in the Graph Explorer there is the button "Get Access Token", where the application can selected, for which the token is to be valid for.
When clicking on it a new window opens where rights can be selected, which the app should posses, as for example that it is allowed to post in the name of the user (for that and maybe other rights too a user has to be selected).

Important: I recommend reading this new post regarding access tokens, since Facebook decreased their validity a lot.

No comments:

Post a Comment