Reputation: 177
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
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
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.
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