degmo
degmo

Reputation: 177

Retrieving data from Facebook ad account

Our organization has two Facebook ad accounts. I want to retrieve marketing insights data (impressions, clicks, spends, etc.) for each ad account weekly and load the data into our warehouse for reporting.

My understanding is that in order to access such data, I will have to create a Facebook App which I did. After creating the App, I added the product Marketing API to the App. I then went ahead linked the two AD accounts to the Marketing API product (I did this by going to the App's dashboard, selecting the Marketing API product under the products section on the left navigation pane, and clicking on settings).

Next, using the Graph API Explorer, I generated an access token for the app and attempted to run a curl query for retrieving some data.

curl -G \
-d "fields=impressions" \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/2.12/9094495844881/insights"

The error I get is:

error":{"message":"Unknown path components:
/9094495844881/insights","type":"OAuthException","code":2500,
"fbtrace_id":"A8oc2/czXYC"}}

What I am doing wrong here? Is the approach wrong to begin with?

Upvotes: 0

Views: 406

Answers (1)

Javi
Javi

Reputation: 126

You need to generate a user access token or create a system user. This is how Facebook verifies you have permission to make requests. Facebook access docs.

User Access Token

Here is how you generate a user token through Facebook's UI. You need to have access to both ad accounts for this to work.

Generating the token

  1. Obtain an access token using the graph explorer.
  2. Make sure to select your app in the “Application:” drop down on the top right corner
  3. Click on the "Get Token" drop down then select "Get User Access Token"
  4. Select the following permissions ads_manage and ads_read.

Requesting a long life token

The token you generated will expire in around a hour so you will need to request a long life token.

  1. Copy the token you just generated
  2. Head to the access token debugger
  3. Click "Extend Access Token" at the bottom

Your now ready to make request to the Insight API.

System User

If your company has a business manager set up I would recommend creating a system user.

During the creation process you will get a token which can be used to make requests. Don't forget to assign the ad accounts to the system user through your business manager.

Upvotes: 1

Related Questions