StarSpot
StarSpot

Reputation: 13

Accessing Facebook Marketing API

I'm trying to create a Facebook ad using the Facebook Marketing API. I haven't used it before and was wondering how I gain access to the API.

I have an access token with ads_management permission but are any other steps necessary and how would I then access the API?

Thank you for your help.

Upvotes: 1

Views: 2492

Answers (2)

Bhaskar Bhuyan
Bhaskar Bhuyan

Reputation: 581

If you talk Python, this might help. Facebook offers a business SDK that abstracts the marketing API, and that way you can access the marketing api with the facebook sdk for python. Do "pip install facebook-business", provide the creadentials and the ads account_id. You are ready to go.

from facebook_business.api import FacebookAdsApi
from facebook_business.adobjects.adaccount import AdAccount
my_app_id = ''
my_app_secret = ''
my_access_token = ''
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
my_account = AdAccount('act_XXXXX')

This will help you get started:

https://developers.facebook.com/docs/business-sdk/getting-started/ https://developers.facebook.com/docs/marketing-api/sdks/

Upvotes: 0

bjeavons
bjeavons

Reputation: 1133

Along with a access token with the appropriate scope you need a ad account and a Facebook application and to authorize the account as an advertiser for the app. Add the account under Advertising Accounts within Advanced settings of your app. See also the Facebook documentation page on Marketing API access at https://developers.facebook.com/docs/marketing-api/access. For now you should follow the Development access level.

To get start with the API you'll need to know your Ad Account ID which you should have from the prior step. If not you can find it from https://www.facebook.com/ads/manager

A simple example of using the API is to make a cURL request for the id and name of your ad account. Replace with your token and with the number ID retrieved from the above step.

curl -G \
-d "fields=name" \
-d "access_token=<ACCESS_TOKEN>" \
"https://graph.facebook.com/v2.4/act_<AD_ACCOUNT_ID>/

For further API documentation see the getting started guide at https://developers.facebook.com/docs/marketing-api/getting-started and also the API overview at https://developers.facebook.com/docs/marketing-api/using-the-api.

Upvotes: 2

Related Questions