Get Started with Branches.FBAPI
Add a reference to the Branches.FBAPI.dll library from the application that will use it. You will also need to import the other library components into your bin folder if they are not automatically added.
If you have a valid Serial Code to unlock FBAPI then add a reference to the appSettings in your project (usually web.config or app.config) like this.
<appSettings>
<add key="FBAPISerial" value="[Your Unlock Key Here]"/>
</appSettings>
Without a serial code you will have 30 days to use this product and will be limited to 250 queries to the Facebook server when your library is compiled. If you recompile then this value will start again from 0.
Important concepts
Setting up the session
The SessionInfo object must be created first. It manages basic information that allows requests to be made to the Facebook server. You can call it one of two ways:
1. Use an existing access_token that you already have
Imports Branches.FBAPI
...
Dim SI As New SessionInfo("[access_token]"))
2. Add your Application ID and Application Secret from Facebook
Imports Branches.FBAPI
...
Dim SI As New SessionInfo("[application_id]","[application_secret]"))
You will need to validate the user to get a valid access_token.
Getting an access_token from Facebook
When you need to authenticate a user through Facebook you can call the AuthenticateUser Function on the SessionInfo Object. This will redirect the user to Facebook where they can be validated and then return them to your site. Once returned you will need to call the ReadFacebookAuthResponse function to get the result of the request.
Make the request
Imports Branches.FBAPI
...
Dim SI As New SessionInfo("[application_id]","applicaiton_secret")
SI.AuthenticateUser("http://[my url]", New SessionInfo.PermissionsEnum(){SessionInfo.PermissionsEnum.email, SessionInfo.PermissionsEnum.read_stream}))
Read the response from the URL you provided above
Imports Branches.FBAPI
...
Dim FSR = SI.ReadFacebooAuthResponse
If validation is successful then the FSR.Authenticated is true and will have an access_token that you can store for future requests.
To make requests use the Functions.Reuqests Object
Create a new object, pass in a valid (contains an access_token) SessionInfo object in the constructor.
Imports Branches.FBAPI
...
Dim SI As New SessionInfo("[access_token]"))
Dim Req New Functions.Requests(SI)
Make a call via one of the functions to get information from Facebook. If you are not authorized by Facebook to access a users information an exception from Facebook will be thrown.
Dim User = Req.GetUserInfo("[optional user ID]")
Response.Write(U.name)
Getting an access_token for a winforms based application from Facebook
This will authenticate the user when a button is clicked on the form.
Imports Branches.FBAPI
...
Getting an access_token for a winforms based application from Facebook
This will authenticate the user when a button is clicked on the form.
Imports Branches.FBAPI
...
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim SI As New SessionInfo("[application_id]","applicaiton_secret")
' Add an event handler so that you can process
‘ the response when the user is authenticated
AddHandler SI.AuthenticationResult, AddressOf ReadResponse
' Call the function to display a form to the user and log them into Facebook
SI.AuthenticateUser(Me, New SessionInfo.PermissionsEnum(){SessionInfo.PermissionsEnum.email, SessionInfo.PermissionsEnum.read_stream}, False)
End Sub
When the process is complete an event call ReadResponse is fired and contains the same response object as in all other authentication steps.
Sub ReadResponse(ByVal FBR As Branches.FBAPI.SessionInfo.FacebookResponse)
Label1.Text &= " - " & FBR.UserID
Me.BringToFront()
End Sub
To Post/Update/Delete information use the Functions.Posts Object
Imports Branches.FBAPI
...
Dim Posts = New Functions.Posts(SI)
Dim P As New Post
P.name = "name of post"
P.message = "message"
P.link = "www.cnn.com"
P.caption = "my caption"
Posts.PublishCreate("[object ID to post to]", P)
Dim PostID = P.id