Unlike targeting a custom audience, it seems impossible to create an ad targeting a saved audience using Facebook Ads API. Can someone confirm that is the case? What would be a workaround? This is the error I'm getting:
Error #100: Param targeting[custom_audiences][id] must be a valid custom audience id
There is a difference between a saved audience and a custom audience. A saved audience is an audience you manually create specifying age range, geographic region and interests. While a custom audience is a list of customers you gathered (uploaded or visitors or your site etc). You can create these audiences manually through the Ads Manager interface:
Using Graph API Explorer, one can retrieve saved audiences as follow:
act_1234567890/saved_audiences
Using Graph API Explorer, one can retrieve custom audiences as follow:
act_123456789/customaudiences
Note that 123456789 is not my real account number. I changed it for security reasons.
So, I can retrieve IDs for both custom audiences and saved audiences and creating an ad targeting a custom audience works fine, unlike targeting a saved audience which gives the above error message.
A cumbersome workaround could be to save the flexible_spec of each saved audience locally and use that spec when creating ads. The problem with that is that some targeting segments become invalid (Facebook decides to discontinue some segments at random times) which causes Facebook Ads API to hickup. Additionally, this means I constantly need to keep saved audiences in sync with my local copy. Unless of course I retrieve the targeting of a saved audience on the fly and re-use it, each time I create an ad resulting in yet another API request.
I figured it out myself. It seems impossible to directly target a saved audience unlike a custom audience, which is odd. What I did is retrieve the targeting from the saved audience first and reuse that targeting when creating the ad.
Here you see a screenshot of the official documentation showing only custom audiences and lookalike audiences can be targeted.
Retrieving targeting from saved audience (with Facebook PHP SDK):
$api = Api::instance();
use FacebookAds\Http\Request;
$response = $api->call(
"/987654321", 'GET',
array('fields'=>'targeting')
);
$audience = $response->getContent();
With 987654321 as the saved audience ID.
Then copy that targeting to the ad (with Facebook PHP SDK):
use FacebookAds\Object\Targeting;
use FacebookAds\Object\Fields\TargetingFields;
$targeting = new Targeting();
$targeting->setData($audience['targeting']);
The disadvantage of this technique is that the ad won't be updated when the saved audience is updated and that it requires an extra API call which slows down the creation of the ad.
Related
My team and I have been trying to connect to the Graph-API (Facebook) for a few days to get access to Audience Network data through our API.
Steps we follow:
Implementation of Facebook Login flow
Generation of Access Token from the Facebook Login Button in our application.
Modification of the Access Token to a Long-Term Token.
We debugged both tokens through the official tool and it is possible to observe that it is a valid token with the proper access: https://developers.facebook.com/tools/debug/accesstoken/
In the settings, the JavaScript SDK is already properly activated
The request we are using as an example is:
https://graph.facebook.com/<API_VERSION>/<BUSINESS_ID|PROPERTY_ID|APP_ID>/adnetworkanalytics/?metrics=['fb_ad_network_imp']&access_token=<ACCESS_TOKEN>
We use the following documentation as reference and tools:
https://developers.facebook.com/docs/audience-network/optimization/report-api/guide-v2?locale=en_US
https://developers.facebook.com/docs/audience-network/optimization/apis/FB-login-Reporting-API
https://developers.facebook.com/docs/facebook-login/guides/access-tokens/get-long-lived
Even after all these steps, when trying to make a request to the Graph-API, through the explorer https://developers.facebook.com/tools/explorer/, we still receive the following message:
"The way to access reporting API v2.0 has changed. You now need to implement Facebook Login for your app to access this API. See instructions here: https://developers.facebook.com/docs/facebook-login/"
Is anyone trying to implement this flow or know how to fix this behavior?
My team has had a FB marketing/business account for 2 years now, and we opened our sandbox account around that time. However, when I run my script to create an audience for the sandbox account, I receive this error:
status: 400,
response: {
error: {
message: '(#2654) Customer List Audiences Are Not Available: Ad accounts owned by businesses new to Facebook Products can create customer file Custom Audiences after several weeks of following our policies.',
type: 'OAuthException',
code: 2654,
error_subcode: 1870054,
fbtrace_id: '*****'
}
},
I've accepted the ToS as many answers have previously suggested. I've been able to populate the sandbox with other data, but creating an audience is giving me serious problems. If anyone has run into this issue or has any suggestions, I'd really appreciate the feedback.
I have a automated job to publish some data to facebook through API, it was working fine until recently it started throwing error
com.restfb.exception.FacebookOAuthException: Received Facebook error response of type OAuthException: Permissions error (code 200, subcode 1870034)
I googled subcode 1870034 but no help, if anyone have encountered this error previously ,please explain regarding this subcode.
Thanks for any help.
Doesn't seem it's related to TOS. For me error looked like
{"error":{"message":"Permissions error","type":"OAuthException","code":200,"error_subcode":1870047,"is_transient":false,"error_user_title":"Audience Size too Low","error_user_msg":"You cannot remove users from this audience because it will result in a low audience size.","fbtrace_id":"xxx"}}
Here you can find an official answer from FB team
https://developers.facebook.com/support/bugs/2093728693993530
Thanks for writing in. I can confirm that this is a valid error message. Custom Audiences must maintain a certain minimum size, though the specific number is not actually documented. I believe the required minimum is approximately 100 unique users. If you need to remove so many users that you're going under this limit, I'd recommend deleting the custom audience entirely.
Also why it's Permissions error...
I'm having the same issue for error subcode 1870034, which seems to come from a Custom Audience TOS issue, here is the full error message
You'll need to agree to the Custom Audience terms before you can
create or edit an audience of CUSTOM type.
You can try accept the Custom Audience TOS using this link https://www.facebook.com/ads/manage/customaudiences/tos/?act=AD_ACCOUNT_ID
(Though you'd probably need to own the ad account in this case)
How to i can watching live tream facebook with access_token
I want to increase the live audience video on facebook with token code.
Mostly I did not find the live view API via the token
There is no support or API end point to view a Live Stream by using Access token of user.
So, you can't increase live audience by using the access token.
It can only be increased by actual viewers viewing it.
I'm trying to set up a custom endpoint to handle opt-out requests from a Facebook custom audience (and setting it as the "opt_out_link" (per Facebook's custom audience documentation). What I don't know is what type of HTTP method to listen for. Should my endpoint be listening for a POST request? Also, what parameters are being sent to that opt out link? The user's ID?
As it turns out, the opt_out_link is just a URL to your existing unsubscribe form. It's displayed in the "Why am I seeing this" modal when you click on an ad.