Skip to content
Fresh 2026

FB.API

Makes a call to the Graph API to get data, or take action on a user's behalf. This will almost always be used once a user is logged in, and an access token has been granted; the permissions encoded by the access token determine which Graph API calls will be available.

Parameters

There are two signatures for FB.API, one for passing a collection of argurments and another for passing more complicated data, like images.

text
public static void API(
        string query
        HttpMethod method,
        FacebookDelegate<IGraphResult> callback = null,
        IDictionary<string, string> formData = null
)

public static void API(
        string query
        HttpMethod method,
        FacebookDelegate<IGraphResult> callback,
        WWWForm formData
)
NameTypeDescriptionDefault
querystringThe Graph API endpoint to call. e.g.<br>/me/scores<br>.none
methodHTTPMethodThe HTTP method to use in the call, one of<br>HttpMethod.GET<br>,<br>HttpMethod.POST<br>, or<br>HttpMethod.DELETE<br>.HttpMethod.GET
callbackFacebookDelegate<IGraphResult&gt;A delegate which will receive the result of the callnone
formDataDictionary<string,string&gt;<br>or<br>WWWFormThe key/value pairs to be passed to the endpoint as arguments.<br>HttpMethod.GET<br>is<br> not <br>supported with<br>WWWFormnone

Best Practices

Many kinds of data available via the Graph API do not change often. For example, users change their profile pictures infrequently, and their friend lists will often be the same between visits to your app. To reduce network I/O and improve your performance, consider reading these items on your server rather than your client, caching the results and then subscribing to realtime updates on those objects so you'll know when to refresh your cached versions.

Be sure to check the value passed into the callback, as it may reflect an error, rather than your desired query output. The most common cause of errors is an authorization problem, such as insufficient privileges or an expired access token; authorization errors look like this:

json
{
  "code":400,
  "body": {
    "error": {
      "message": "An active access token must be used to query information about the current user.",
      "type": "OAuthException",
      "code": 2500
    }
  }
}

See also our guide to using JSON with Unity.