How to create multiple adsets using facebook marketing api - facebook

I am trying to target multiple lat-long(more than 200). There is a option of multiple ad sets in Facebook power editor but how to achieve this with Facebook Marketing API using curl. After doing a lot of research found this
https://developers.facebook.com/docs/marketing-api/reference/ad-campaign
but it's just showing multiple adsets information and except this I did not found any other explanation on facebook marketing api doc to create an ad using multiple ad sets.

Couldnt comment under 50 :)
Here is your solution :
https://developers.facebook.com/docs/marketing-api/buying-api/targeting/
EDIT: if you want to create multiple ads this video will help you :
https://www.youtube.com/watch?v=pq1y_Ze-0g8
if you want to target multiple with lat and long.
use FacebookAds\Object\TargetingSearch;
use FacebookAds\Object\Search\TargetingSearchTypes;
$result = TargetingSearch::search(
TargetingSearchTypes::GEOLOCATION,
null,
'un',
array(
'location_types' => array('country'),
));
for more info :
https://developers.facebook.com/docs/marketing-api/targeting-search/

Related

Google Ads REST API: The operation is not allowed for the given context., at operations[0]

I was trying to create a campaigBudget:mutate with all information that Google Ads API ask for, but no result, they show me only one error :
The operation is not allowed for the given context., at operations[0]
this screenshot may help you guys:
HEADER:
BODY (Req & Res):
and this is an example from Google Ads API:
Thank you
After research I found that the problem was CUSTOMER_ID
In header we should set : login-customer-id => MANAGER_CUSTOMER_ID
and in endpoint url we should set : /customers/CUSTOMER_ID/campaignBudgets:mutate

facebook-java-sdk unable to create "Ad", says using instagram a/c as placement when not really using anything

I am trying to create Ad using facebook-java-sdk
val adCreative = new AdAccount(ACCOUNT_ID, context).createAdCreative()
.setName(s"Test Creative +$TEST")
.setObjectStorySpec(
new AdCreativeObjectStorySpec()
.setFieldLinkData(
new AdCreativeLinkData()
.setFieldCaption("http://www.field-caption.com")
.setFieldImageHash(attachment1.getFieldImageHash)
.setFieldLink("http://www.google.co.in")
.setFieldMessage("try it out")
)
.setFieldPageId(FACEBOOK_PAGE)
)
.execute()
val ad = new AdAccount(ACCOUNT_ID, context).createAd()
.setName(s"Test Ad +$TEST")
.setAdsetId(adSet.getId)
.setCreative(adCreative.getId)
.setCreative(new AdCreative().setFieldId(adCreative.getId()))
.setStatus(Ad.EnumStatus.VALUE_PAUSED)
.execute()
However the createAd calls fails and results into exception with
com.facebook.ads.sdk.APIException$FailedRequestException: {"error":{"message":"Invalid parameter","type":"OAuthException","code":100,"error_subcode":1772103,"is_transient":false,"error_user_title":"Instagram Account Is Missing","error_user_msg":"You're using Instagram as a placement. Please select an Instagram account to represent your business in your Instagram ads, or select a Facebook Page to use instead.","fbtrace_id":"FtpWRXVY1tH"}}
This was working fine couple of days back, but all of sudden has started throwing an exception. Any help would be appreciated.
I'd like to add to this answer since i just fought with this issue.
Our long running app that managed boosting just stopped working this month and was throwing the error the OP mentioned.
It appears that the default settings on Facebook's side changed. The docs state that the defaults are facebook, audience_network, messenger
Looking in the Ads Manager, it shows that the placement for the failed boost attempt now includes instagram as a placement. There doesn't seem to be any mention of this change anywhere that I could find.
So I did have to change the call to explicitly define facebook, audience_network, messenger as my publisher_platform setting and not rely on the defaults.
You can explicitly specify publisher platform to publish only on facebook
val adSet = new AdAccount(ACCOUNT_ID, context).createAdSet()
.setName(s"Test AdSet +$TEST")
.setLifetimeBudget(20000L)
.setStartTime(currentDateTime.toString())
.setEndTime(currentDateTime.plusDays(1).toString())
.setCampaignId(campaign.getId())
.setIsAutobid(true)
.setBillingEvent(AdSet.EnumBillingEvent.VALUE_IMPRESSIONS)
.setOptimizationGoal(AdSet.EnumOptimizationGoal.VALUE_POST_ENGAGEMENT)
.setTargeting(
new Targeting()
.setFieldCustomAudiences(List(idNameCusAudience).asJava)
.setFieldPublisherPlatforms(List("facebook").asJava)
)
.setStatus(AdSet.EnumStatus.VALUE_PAUSED)
.execute()
None of these answers really answer what you need to do if you want to include Instagram.
In order to post to instagram you need an instagram account ID.
Every single page on Facebook has (or can have) an instagram 'account' without the user creating one.
What you need to do is (in this order):
Check if they have an instagram linked (if they do you use this ID)
Check for page_backed_instagram_accounts to see if their page has an instagram account that Facebook made for them to be able to advertise (this account is hidden and cannot be found on instagram) if they have this, use the ID from this account.
If for some reason their page has no instagram nor does it have page_backed_instagram_accounts then you will need to create a page_backed_instagram_account
The endpoints you are looking for are:
https://graph.facebook.com/v3.1/[pageId]?fields=instagram_accounts
https://graph.facebook.com/v3.1/[pageId]?fields=page_backed_instagram_accounts

How to get the Ad final url with the Facebook insights API

I'm trying to get an ad final url using the python sdk.
I tried all the fields but I can't manage to find one which returns the ad url. At the moment my fields are:
params = {'access_token':creds.refresh_token,
'fields':'action_values, actions, ad_name, adset_name, objective, outbound_clicks, outbound_clicks_ctr, call_to_action_clicks, campaign_name, cost_per_unique_click, cpc, cpm, spend, website_ctr, date_start, date_stop',
'action_breakdowns':['action_link_click_destination'],
'date_presets':'last_year',
# 'time_range':" since:2017-06-01, until:2017-01-03}"
}
ad_insights = requests.get("https://graph.facebook.com/v2.10/{}/insights".format(ad['id']), params=params)
I understand that some ads won't have a final url, like boosting posts, but many ads are only pointing to a site, how can I get the "call to action url" ?
You have to pull in the adCreative for each ad that AdInsights reports on. The adCreative will contain the outbound link.
See here https://developers.facebook.com/docs/marketing-api/reference/ad-creative
The following fields may be of interest to you
object_url
url_tags

FaceBook FQL Query Not Working

We have used the v2.0 graph API & FQL(FaceBook Query Language) for getting the FaceBook details in our project. But recently the result is empty.
I have checked the developer.facebook.com and i found one solution that is Login Review process. We need to get the FB details means we need to get the pre approval from FB.(user_photos, user_videos) It'll work perfectly or not ?
https://developers.facebook.com/blog/post/2015/04/28/april-30-migration/
Sample Code :
args = "SELECT uid,name FROM user WHERE uid = me()"
file = urllib2.urlopen("https://api.facebook.com/method/fql.query?" + urllib.urlencode(args), timeout=3)
Please give some suggestion to fix this problem.
https://developers.facebook.com/docs/apps/api-v1-deprecation
Advance Thanks :)
Have a look at
https://developers.facebook.com/docs/apps/changelog#v2_1_deprecations
The FQL and REST APIs are no longer available in v2.1: Previously announced with v2.0, apps must migrate to versioned Graph API calls starting with v2.1.
You're querying the REST API which is deprecated, as cited. Use https://graph.facebook.com/fql instead.

Can Facebook CPA ads be optimized based on pixel fires?

When ad type is set to "CPA", is it possible to use "offsite_conversion" with pixels, as we can do with "oCPM" ads?
For example, why can't I use the following:
$fbRequest['bid_info'] = array('ACTIONS' => $cData['creative_max_bid'] * 100);
$fbRequest['bid_type'] = 'CPA';
$fbRequest['conversion_specs'] = array('action.type' => array('offsite_conversion'), 'offsite_pixel' => $pixelRemoteId);
This kind of syntax works perfectly for oCPM ads but I wanted to try using CPA ads instead.
Instead, when I try to post the above to FB API, I get an exception with instructions to use "link_click" action instead.
Thank you,
Dan
According to the CPA documentation, no, CPA ads can't be used with offsite conversion pixels, only the actions listed in the documentation can be bid as CPA
Page Likes, Offer Claims, Offsite Link Clicks, Mobile App Installs