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.
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.
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/
Related
Facebook recently released a step-by-step documentation for using a GrapAPI to manage Instagram messages. To obtain the access token to use it, it's necessary to create an application in the developer center, enable login via Facebook and include the permissions "instagram_basic", "instagram_manage_messages" and "pages_manage_metadata" but to activate these options it's necessary to submit various information for approval as statement of how the integration works and descriptions of the usage flow. I don't have access to this information because I can't develop an integration without it being approved.
It's not possible to use the provided test user as the pages raised by him cannot be linked to Instagram accounts.
Tutorial followed: https://developers.facebook.com/docs/messenger-platform/instagram/get-started
Someone with some experience with the Facebook API could give me a light on how to obtain the token with access required and proceed the tests?
I have done the tutorial as well, I faced the same problem. To enable instagram_basic, instagram_manage_messages and pages_manage_metadata without app review you need to create a test-app. For test apps all permissions are granted without review.
Instructions on how to create a test-app
Another usefull tipp: If you are wondering why you need to implement facebook login to access the instagram messaging api, the logic is the following: You need to implement login to then use your own implementation to logg in your own account and obtain the page access key that will let you do api calls to the instagram messaging api. This process is obviously overkill and instagram is working on a way of getting that access token through the developer dashboard.
For now to obtain that access token you need:
implement facebook login as a simple html website and console log the response. Be sure to add the required permissions to the data-scope attribute of the facebook login button:
<div
class="fb-login-button"
data-scope="public_profile,email,instagram_basic,instagram_manage_messages,pages_manage_metadata,pages_messaging"
></div>
deploy to a website that has https enabled (logging in from
localhost will only work if you use a tunelling service like ngrok).
Open your website that has facebook login implemented and logg in with your facebook account that is also linked to the target instagram account and also is admin of your test-app.
get the access token from the response to call the other API endpoints.
I am new to FB's API
I need to use FB Ads Insights API to pull the stats and store in DB. This is my customer's requirement. Now, I have a Developer account and access to my customer's username and pwd, how can I use their credentials and get the access token to query Insights API
TIA,
Use this guide to generate an access token. You will have to create a system user that has access to your customer's account.
I am using Facebook as advertising platform to promote my application on Apple and Google stores. I would like to make windows service which will download daily report(s) about advertising status of my marketing campaign running one Facebook, preferably using 60 day token, or some permanent solution so that token is retrieved when required. I think that i understand everything to do this except how to generate access token to use it with Facebook Graph API. Which token for which Facebook account do I need and how to obtain it?
You'll need a Facebook app and to grant that app the ads_read permission in order to retrieve reports about your advertising efforts via the API (source).
You'll want a long-lived token so that you don't have to re-authenticate very often. The access token documentation details the steps to exchange a short-lived token for a long-lived one.
You may also want to consider managing the app, ad account, and access tokens (via a business system user) with the FB Business Manager.
Create a facebook app.
Go to the Graph API Explorer in Facebook's Tools & Support section.
Pick your app from the drop down.
Hit Get Token > Get User Access Token.
In Select Permissions choose required permissions or select them from extended permissions.
Use the user access token that will be presented to you in the access token form input field.
I'm just getting set up with the ads api at my work using cURL. I've been able to successfully authenticate and get data about my ads and I am now trying to create a newsfeed creative for the page. (Specifically one of the new multi product ones, but this example will just be for a basic "object_story_spec" creative).
When I try to post the creative, I get this error:
{"error":{"message":"(#272) This Ads API call requires the user to be admin of the application. User <page_id> not admin or developer for application <app_id>.","type":"OAuthException","code":272}}
Essentially it seems to be telling me that the page needs to be listed as a developer or admin on the app, but I tried this and there is no option to do that. What am I missing here? I am guessing it is some sort of issue with how I generated the access token, which is a page access token generated from the graph api using my own access token that I generated. Any help is tremendously appreciated!
Here is my code (anything in <> was redacted by me):
curl https://graph.facebook.com/act_<account>/adcreatives
-F "name=Link Page Post Ad Creative"
-F "object_story_spec={'page_id':<page_id>,'link_data':{'message':'Try it out','link':'http://example.com','picture':'http://example.com/pic.jpg'}}"
-F "access_token=<access_token>"
I am building a facebook app and for that I need to create a fake fb user for each user that signs up into my app.
Is there an api available for creating facebook users?
Any help is appreciated.
For testing purpose you can create test user with API. The document is provided here. By specifying installed=true parameter, your app is authorized by default. It's just easy as below:
curl -X POST \
-d "installed=true" \
https://graph.facebook.com/{app-id}/accounts/test-users