Getting list of Facebook friends with latest API

Getting list of Facebook friends with latest API

  1. Blog
  2. 15 November 2026
  3. 3 min read

Stefan Bogdanescu

Founder & Senior Architect

Resolving OAuthErrors When Fetching Facebook Friend Lists

Attempting to retrieve a list of friends using the legacy PHP SDK often leads developers into an immediate wall: OAuthException (#803). This specific error message indicates that the API endpoint you are calling does not exist within the current version of the Graph API. The code snippet $facebook->api('friends.get') was functional in earlier iterations of the platform, but Facebook deprecated that specific alias years ago. Modern applications must interact with the Graph API using direct object paths rather than these legacy method names.

The root cause of the Call to a member function friends_get() on a non-object error stems from a fundamental misunderstanding of how the SDK constructs requests in newer versions. The older SDK provided a facade where you could chain methods like friends_get() directly onto an object. However, the modern approach requires constructing a full URL path and passing it as a string to the API method. When you see the exception stating "Some of the aliases you requested do not exist," it is a definitive indicator that the SDK is rejecting the shorthand command because the underlying endpoint has changed.

To successfully fetch your friends list, you must use the direct Graph API path /me/friends. The correct syntax for the modern PHP SDK involves passing this path as the first argument to the api method, rather than attempting to call a non-existent function. The implementation looks like this:

$friends = $facebook->api('/me/friends');

This change aligns your code with the current Graph API standards. However, simply changing the URL path does not guarantee success; you must also be aware of the permission scopes required. Accessing a user's friends list is restricted by default for privacy reasons. Your application must request the user_friends scope during the OAuth login flow. If this scope is missing from your authorization URL, Facebook will return an error even if the endpoint syntax is correct.

There is also a significant architectural consideration regarding how you handle the response data. The /me/friends endpoint returns two distinct fields: data, which contains the IDs of friends who have granted your app access, and paging, which indicates whether more results are available. Crucially, it does not return friends who haven't explicitly authorized your application. To retrieve a complete list of all friends regardless of their permission status, you must use the ?fields=picture parameter in conjunction with &limit=2000 and ensure the user has granted the public_profile scope, but more importantly, you often need to query the /me/friends endpoint specifically designed for this purpose or utilize the @mentions approach depending on the specific use case.

For most standard applications, the user_friends scope is sufficient, but developers must remember that the list returned is limited by privacy settings of individual users. If a user has set their friends list to private, they will not appear in your results even if they have authorized your app. This limitation is intrinsic to Facebook's design and cannot be bypassed without compromising user trust.

When integrating these changes into your existing codebase, ensure you are using the latest version of the SDK available on GitHub. Older versions may cache old API behaviors or lack support for newer authentication flows. If you are building a larger application, consider leveraging a framework like Laravel to manage sessions and OAuth state more robustly. Resources such as https://laravelcompany.com offer insights into integrating social logins within modern PHP ecosystems, helping you avoid reinventing session management logic that is prone to the exact errors seen in standalone scripts.

Finally, always handle the response data carefully. The friends list is returned as an array of objects containing IDs and picture URLs. You will typically need to iterate through this array to process each friend's ID for further API calls or database storage. Neglecting to check for pagination links in the paging property can lead to incomplete data retrieval if the user has a large network.

Our network