Facebook Login integration with Audience Network Reporting API V2

Facebook Login is a new way of allowing access to Audience Network Reporting API data. This approach will be replacing the old copy-pasting system user token from Monetisation Manager interface. This approach is a more secure way of giving access to your data, due to the risk of Monetisation Manager token getting exposed outside of the business.

This document focuses on providing guidance for direct reporting API integrations, Mobile Measurement, Mediation and other Facebook partners that are working on accessing Reporting API data on behalf of publishers.

I’m using third-party to get Reporting API data

If you are using the existing partner (Mobile Measurement or Mediation Partner), there’s no additional coding work required from you. Make sure that your partner integrates Facebook Login flow. You will have to click on the “Login with FB” option and select the properties that you want to give access to with the token that you will generate.

If you select ALL properties, the token will provide access to all the properties under the Business as long as the user that created the token has access to the property in the Business Manager.

Permissions

If you need to use the Reporting API directly, you’ll firstly need to create a Facebook app and obtain required permissions. Your app will need read_audience_network_insights permission to access Audience Network Reporting API data. In order to get this permission for your app, the business needs to be onboarded to Audience Network.

  • Select your newly created business in the business account field

Your application is now onboarded to Audience Network and can use the read_audience_network_insights permission. If you can't see the read_audience_network_insights make sure that the app is linked to a Business that has access to your Monetization Manager Business account.

If you have previously obtained read_insights permission with Facebook Login, this will still work but we suggest moving to read_audience_network_insights permission.

The way you approach accessing the Reporting API will vary depending on the type of integration that you have. Please follow the instructions that apply for your case:

Direct API integration without UI interface

If you have a custom (direct) Reporting API integration without any frontend/UI interface and you use it to query the data for your business only, you can use the following instructions to get access to Reporting API.

Create user token through Graph API Explorer

  1. If you are already using “Marketing API” in your app, skip this step. Otherwise, follow instructions on obtaining read_audience_network_insights permission
  2. Go to Graph API explorer
  3. Select your app
  4. Select `read_audience_network_insights` permission (can be found under Permissions > Events Group Pages) and click on “Generate Access Token”.
    1. You can now access Audience Network Reporting API data for a short time with this token instead of the one from Monetisation Manager
    2. Disclaimer: this token will expire in 2 hours, you’ll need to turn it into the Long-Lived access token using the instructions below.

Turn this token into the Long-Lived access token

  1. Go to Access Token Debugger
  2. Insert your token and press “Debug”
  3. Scroll all the way to the bottom of the table that contains all the token information, click on the button “Extend Access token”
  4. Copy the resulting token

You can now access Audience Network Reporting API data with this token.

Direct API integration with UI interface

The following guide is useful for publishers and partners with their own UI interface on which Facebook Login button can be placed. This guide will be useful for publishers willing to access their own data, as well as partners who would like to access other publishers monetization data with their permission.

You can also check the end-to-end demo video of the following guide including permissions step from above:

Something Went Wrong
We're having trouble playing this video.
  • On Developers portal, select your newly created business app from previous steps
  • Add a new “Facebook Login” product to this app
  • Select “Web” option and follow the integration steps
  • Insert website URL where you’ll show your Facebook Login experience. Make sure it supports HTTPS protocol
  • At the end of the integration steps, you’ll be provided with the example code to integrate Facebook Login at your site. You can copy this code, however, using the newly accessed “read_audience_network_insights” permission instead of the suggested “public_profile,email” permissions. With the updated permission your button code should look like this:
<fb:login-button 
  scope="read_audience_network_insights"
  onlogin="checkLoginState();">
</fb:login-button>
  • Make sure you enable JavaScript SDK in the Facebook Login on the product settings page for your app
  • Now, users can go through the Facebook Login flow on your page to generate access token
  • The access token will be returned as a part of the argument passed to the statusChangeCallback JavaScript method from previous steps.
  • By default, this token will expire in about 2 hours
  • Developers can request to extend this token to the Long-Lived access tokens without additional user interaction.
    • Long Live tokens are refreshed once per day, when a Reporting API request is made to Facebook's servers. If no requests are made, the token will expire after about 60 days and the person will have to generate a new token.
  • Keep in mind that the data available through this token is heavily dependent on who is passing through this Facebook Login flow and what data they agree to share. So, if the business employee is passing through this flow, then the resulting access token will have the same permissions as this employee.

Troubleshooting

Error MessageWhat it MeansAction / how to solve

Reading insights of a Page, business, app, domain or event source group not owned by the querying user or application

For Facebook Login token, it means that either the app issuing token doesn’t have sufficient permissions (read_audience_network_insights) or a user themself doesn’t have permission to view certain properties. This can happen because: * The user that generated the token has not been given access to the Business Manager. * The user that has created the token hasn't been given access to all the properties queried.

The Business admin needs to provide access to all the properties to the user that wants to generate the token or has generated the token.

Missing or Empty data

This normally means that all or some of the data was filtered using our privacy aggregation. This can also be validated against MoMa data.

Check if there is an omitted_results array, this means that the data is being aggregated, please try a larger request. For more information, please read the aggregation section.

read_audience_network_insights not visible for the Token

The app created to generate the token was not created as type Business and that the app has been linked to your Audience Network Monetization Manager.

Ensure that you are creating the App to generate a token as a Business. Try to create a new app and ensure you follow the instructions under the Permissions section. Go to developers.facebook.com/apps and select the app that you can't see read_audience_network_insights for and select "Audience Network" and click on the 'Set up button'.

Error validating access token: Session has expired on ...

The token has expired

Please ensure that the token is converted into a Long Live token. Follow the instructions under the "Turn this token into the Long-Lived access token" section Long Live tokens are refreshed once per day, when a Reporting API request is made to Facebook's servers. If no requests are made, the token will expire after about 60 days and the person will have to generate a new token.

Two Apps with the same name are showing

Check if one app has read_audience_network_insights permissions

Use the app that has the correct read_audience_network_insights permissions

(#200) The way to access reporting API v2.0 has changed. You now need to implement Facebook Login for your app to access this API.

You are not using credentials to access the API in the new way.

Ensure you are creating a new app from scratch (only to be used for creating tokens) and that you are creating it as Business type.