Using Facebook Graph API After Login

First published: 2015-09-29      |      Last updated: 2026-01-29

Facebooks Graph API gives you the ability to better understand and target content to your user. In this blog we go over some useful implementations of the Graph API that you can use to pull in user data as well as publish on your users behalf.

Getting Your Site Ready

The first thing you will need to do is implement an authorization interface that will allow your users to Login with there Facebook credentials and grant access to your application to handle the features that we will go over in this blog.

You can refer to this article on setting up a Facebook Login integration: Implement Facebook Social Login

While implementing the Login detailed in the above blog you can modify the scope included in the Facebook button to request the scopes that we will be using.

Define your Facebook button as follows:

1<!-- -->

This will cause your interface to request additional permissions that may require you to submit your app for review in order for your users to get access to these permissions.

Managing your users login credentials.

After your user has authenticated you can capture the users access token for use in your application or backend systems. During the Facebook login in the function function statusChangeCallback you can check the response for an active Facebook session and store the access token from this object as follows:

1if (response.authResponse) { var access_token = FB.getAuthResponse()['accessToken']; }

This token is valid for 2 hours by default and can be upgraded to a long lived with a server-side call as detailed here: Access Tokens for Meta Technologies

The long lived token will be valid for 60 days over which you will be able to access the users data or handle actions that they have granted your app permissions.

If you have stored an access token or long lived token and wish to reinitialize the Facebook JavaScript graph API you can handle this by including the following parameter when making FB.api calls:

1FB.api( '/me', 'get', { access_token : 'access_token_for_some_user_fetched_from_your_database' } );

Getting User Data and Specific Fields

The simplest way to get a copy of the User Profile object is to access the /me endpoint:

1FB.api('/me', function(response) { });

This will this will return the users name and an ID by default. You can add additional field requests to the me endpoint in order to retrieve further data-points for the user. Below we request the users id, name, age_range, bio, birthday, and email using a stored access-token.

1<!--FB.api( '/me?fields=id,name,about,age_range,bio,birthday,email', 'get', { access_token :  },function(response) { //Handle Data Here it will arrive in a Json object in the response } );-->

There are additional edge cases which can be accessed through the /me endpoint. A full list can be found here. A below sample details how you can retrieve the videos that the user is tagged in or has uploaded.

1<!--FB.api( '/me/videos', 'get', { access_token :  },function(response) { //Handle Data Here it will arrive in a Json object in the response } );-->

Publishing Content to a Users Wall

In order to publish content to a users wall you will have to have requested the publish_actions permission during login which we have done in the first part of this article. You can then access the following endpoint to publish a status post to a users wall:

1<!--FB.api( '/me/feed?message=', 'Post', { access_token :  },function(response) { //Handle Response which will contain a Post ID if successful } );-->

Conclusion

Facebook offers many options to integrate their API into your site and offers a variety of easy to use SDKs for multiple languages. Check out their documentation for details on the various SDKs and additional graph endpoints.

Karl Wittig
By Karl WittigKarl Wittig serves as the Vice President of Customer Success at LoginRadius, where he bridges the gap between complex identity architecture and seamless customer implementation. With a formal background in Computer Engineering, Karl brings a 'builder’s mindset' to the customer journey.

Beyond post-implementation success, Karl is a core contributor to the LoginRadius technical ecosystem. He played a pivotal role in developing the LoginRadius Admin Console, SDKs, and API Documentation—tools used daily by thousands of developers. As the Lead Solutions Engineer for presales, he works at the intersection of product strategy and real-world feature design, ensuring that the LoginRadius roadmap is directly informed by enterprise security requirements.
cardImage

The State of Consumer Digital ID 2024

cardImage

Top CIAM Platform 2024

cardImage

Learn How to Master Digital Trust

Customer Identity, Simplified.

No Complexity. No Limits.
Thousands of businesses trust LoginRadius for reliable customer identity. Easy to integrate, effortless to scale.

See how simple identity management can be. Start today!