
As a general Facebook user, when we go to use a Facebook application, we get a window titled ‘Request For Permission.’ After clicking the ‘Allow’ button, we can enter the application. This is a very usual scenario. It’s a crucial stage for developing a Facebook application, where a couple of things must be noticed very carefully to create the process in the most suitable way. Here, I will give some essential tips that you should follow when creating a Facebook application and implementing Facebook authentication.

Do you need Facebook API authentication at all?
In many cases, it’s possible to integrate Facebook’s provided functionality for the social optimization of your site very quickly, without any need for an authentication process. Facebook provides these as simple HTML code snippets, which are iframe-based. Those codes on iframe automatically detect a member’s session and provide options to contribute to the site by his activities. These are very well-known activities, such as ‘Like,’ ‘Share,’ ‘Comment,” Live streams, ‘ etc. So, if your needs are something around these, you shouldn’t be worried about implementing authentication at all.
Ask for proper extended permissions:
Now, we need user authentication so that we can access some of the users’ private information and write data for users’ Facebook streams. It would help if you remembered that, your application is getting permission that doesn’t mean that you can access whatever you want. There are a lot of Facebook API methods which require special extended permission before they can be accessed. So, measure your application purpose first, what kind of permissions you may need and then add them while implementing the authentication process.
For how long do you want the user to authenticate:
You must remember that, in general, traditional authentication session time to access private data from your is limited, and it expires after a specific time. If you want the user to access your application in future without authentication again, you will have to get an ‘offline_access’ extended permission, which doesn’t have any expiry time, so you can save that against a user and use it as many times as you need. The best and easiest way to do this is to save the access token in a cookie with a long expiration duration and retrieve it whenever a user tries to access the application.
Does your application require offline access permissions?
It would help if you also determined whether you will need access to the user profile to retrieve private data, publish data to the user’s timeline, etc. when the user isn’t online/not using the application. If you need so, you will be required to get ‘offline_access’ extended permission as in the previous point. However, it won’t be enough to save the access token in the cookie this time, as you will need to access this beyond user interactions. The best way to get this done is to save the access token to the database along with the user ID so that you can retrieve it later when needed.
References:
For official documentation, you can use Facebook authentication overview. If you are trying to find practical ways/code samples to implement Facebook API authentication(especially retrieving the access token, as this is the central part) and you are a C# developer, then refer to my other article on getting a Facebook API access token in c#. I hope this will help you. If you need anything else, let me know. Happy coding 🙂
Discover more from CODESAMPLEZ.COM
Subscribe to get the latest posts sent to your email.
Your website is very interesting and detail but I want to ask you some related to FB authentication. After I authenticate my app and then I can access to FB data which means what I need but after that I want to access to FB data again in the next page, after loading new page but I can’t access or get any data from
FB it seems like I haven’t authenticated the app. (I use php and php sdk)
Rana, it si very helpful all the code and examples you show here thank you very much for that.
I want to thank you rather than asking for things but pelase allow me to ask you this, I am trying to make a system (Asp.NET c# website) that searches for posts in Facebook that contains some key words and to retrieve the number of likes/comments/shares and texto fo the post, I have spent several hours to try to figure out how to accoplish this and I find nothing clear, do you know any guide or good starting point to do so?
Many thanks again.