1 . What's different between the marketing-api optimization goal and FB BM's optimization goal?

Answer :

Facebook's ads manager actually hides the real optimization goal and billing event. There's only a selectbox called Optimisation for Advert Delivery (in Budget & pricing section), which contains some (probably preferred ones) of available optimizations for the adset you're creating. Those values can be mapped to pairs of optimization goal + billing event. You can read the real values using Graph API.

Not all optimization goals are applicable for all objectives, so the values in the selectbox will differ based on selected objective. 


Leave a Comment

Name  
  Email   
Message
1 . Using multiple .replace calls on an array of variables in Javascript / jQuery?
 

Answer :

Just make an array with replacement pairs:

var replacements = [ ["&", "&"], ["'", """] etc

and apply them one by one:

replacements.forEach(function(pair) {
     msg = msg.split(pair[0]).join(pair[1]);
});

split/join is better to replace literal strings than .replace which is intended for use with regular expressions.

Also, your encoding doesn't look right, ® will be displayed as ®, not as ®


2 . Adding facebook like button creates new page. Possible to merge/fix?

Answer :

You can change the href attribute to the page you've already created.
You cannot use the og-tags on your own homepage then but the Facebook-Page attributes are used.

so change

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2Fwww.mywebsite.com&amp;layout=standard&amp;show_faces=true&amp;width=450&amp;action=like&amp;font&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:450px; height:80px;" allowTransparency="true"></iframe>

to

<iframe src="http://www.facebook.com/plugins/like.php?href=http%3A%2F%2F*your facebook page (with escaped slashes and so on)*&amp;layout=standard&amp;show_faces=true&amp;width=4

3 . Facebook Graph API - getting daily spend per ad set?

Answer :

There is no need to do this on the adset level. With calls to the Ad Insights API what you can do is specify a specific aggregate for the data at a defined object level. Given that you have fetched your ad accounts from the /me/adaccounts endpoint you should then be able to do the following:

1. Graph API Request

The following request in the Graph API explorer, or via cURL (both provided) should return you the spend for the entire account:

1a. Graph URL

https://graph.facebook.com/<VERSION>/act_<ACCOUNT_ID>/insights?fields=spend&level=account&date_preset=yesterday&access_token=<ACCESS_TOKEN>

1b. cURL

curl -G \
-d 'level=account' \
-d 'fields=spend' \
-d 'date_preset=yesterday' \
-d 'access_token=<ACCESS_TOKEN>' \
https://graph.facebook.com/<VERSION>/act_<ACCOUNT_ID>/insights

2. Marketing API SDK

$account = new AdAccount('act_<Ad_ACCOUNT_ID>');

$params = array(
  'level' => 'account',
  'date_preset' => InsightsPresets::YESTERDAY,
  'fields' => 'spend',
);

$account->getInsights(array(), $params);

I believe that the above should help you. I have tested with the 1a & 1b and it works perfectly but haven't fully tested with 2.


4 . Deeplinking using GWT History Token within a Facebook iFrame Canvas?
 

Answer :

This may seem to be a hack but here it goes.

Facebook allows the application to tack on parameters to the url ?x=123

So I'm checking the window location to see if it contains my special 'page' parameter and loading that page. Below is my solution given that I'm using GWT + gwt-presenter's PlaceManager class.

The application deep url ends up being 

    EventBus eventBus = injector.getEventBus();

    // Load PlaceManager so it can start listening
    PlaceManager placeManager = injector.getPlaceManager();
    String currentPlace = History.getToken();

    String place = Window.Location.getParameter( "page" );
    if (place != null && !place.isEmpty()) {
        // send user to the place on the URL line
        eventBus.fireEvent( new PlaceRequestEvent( new PlaceRequest( new Place (place) ) ));

    } else if ("".equals(currentPlace)) {
        // Nothing in URL, load default GWTpage
        eventBus.fireEvent( new PlaceRequestEvent(new PlaceRequest( IndexPresenter.PLACE)));

    } else {
        // fire a body to the Place Manager to activate the requsted Place
        placeManager.fireCurrentPlace();
    }

5 . Can't get AdCreative ObjectStorySpec?

Answer :

object_story_spec can be read back from an adcreative when it was used in the creation of that adcreative. If an object is created first it can be linked to an adcreative using object_story_id but that does not populate object_story_spec, the field will be NULL or not returned at all from Graph API.

object_story_spec is a helper method for creating objects (e.g. page posts) inline to creating a ad creative. See for more info on these fields and try out one of the example code snippets to see object_story_spec returned on a read request when it is used on the create request.



6 . What is OpenID “Automatic Login”?

Answer :

I'm pretty certain that this is just an application of OpenID's "Immediate mode":

Immediate mode allows you to attempt to verify the user without them leaving your site at all. This is normally possible if, during the first time you attempt to verify a user, they choose to always allow you to verify them and offers a slightly more streamlined login experience.


7 . How can I check Delivery Status of campaign on Facebook Marketing API?
 

Answer :

Effective_status gives you the effective status of this campaign. For Campaign object, effective_status value can be one of these

ACTIVE, PAUSED, DELETED, PENDING_REVIEW, DISAPPROVED, PREAPPROVED, PENDING_BILLING_INFO, CAMPAIGN_PAUSED, ARCHIVED, ADSET_PAUSED

If you read the effective_status field for adset level, it will tell you if the adset has CAMPAIGN_PAUSED or PAUSED.

EDIT: You will need to combine this field with end_time to determine whether the ad set is completed.


8 . How to get insights for all campaigns in single query + Facebook marketing api?
 

Answer :
class FB(object):
    def __init__(self):
        me = AdUser(fbid='me')
        self.my_account = me.get_ad_accounts()[0]

    def fb_creativies(self, since, until):
        """
        This function is used to get destination url
        for each creative object
        """
        fields = [AdCreative.Field.object_story_spec]
        params = {
            'time_range': {
                'since': since,
                'until': until,
            },
        }

        return self.my_account.get_ad_creatives(fields=fields, params=params)

9 . Facebook ad creative with call to action returns no permission for call_to_action?
 

Answer :
use FacebookAds\Object\AdCreative;
use FacebookAds\Object\AdCreativeLinkData;
use FacebookAds\Object\Fields\AdCreativeLinkDataFields;
use FacebookAds\Object\AdCreativeObjectStorySpec;
use FacebookAds\Object\Fields\AdCreativeObjectStorySpecFields;
use FacebookAds\Object\Fields\AdCreativeFields;
use FacebookAds\Object\Values\AdCreativeCallToActionTypeValues;

$link_data = new AdCreativeLinkData();
$link_data->setData(array(
  AdCreativeLinkDataFields::MESSAGE => 'try it out',
  AdCreativeLinkDataFields::LINK => '<URL>',
  AdCreativeLinkDataFields::CAPTION => 'My caption',
  AdCreativeLinkDataFields::CALL_TO_ACTION => array(
    'type' => AdCreativeCallToActionTypeValues::SIGN_UP,
    'value' => array(
      'link' => '<URL>',
      'link_caption' => 'Sign up!',
    ),
  ),
));

$object_story_spec = new AdCreativeObjectStorySpec();
$object_story_spec->setData(array(
  AdCreativeObjectStorySpecFields::PAGE_ID => <PAGE_ID>,
  AdCreativeObjectStorySpecFields::LINK_DATA => $link_data,
));

$creative = new AdCreative(null, 'act_<AD_ACCOUNT_ID>');

$creative->setData(array(
  AdCreativeFields::NAME => 'Sample Creative',
  AdCreativeFields::OBJECT_STORY_SPEC => $object_story_spec,
));

$creative->create();

10 . How to get Potential Reach from Facebook Marketing API using Ruby on Rails 5?
 

Answer :

Turns out, it's because of the post request. I should be using a GET request instead. Here's the working code for me with the additional interest parameter for the targeting spec.

def get_target(interest_id, interest_name)
    account_id = @account_id
    access_token = @access_token
    url = "https://graph.facebook.com/v2.10/act_#{account_id}/reachestimate"

    params = {
      "access_token" => access_token,
      "targeting_spec" => "{" +
          "\"geo_locations\": {\"country_groups\":[\"Worldwide\"]}," +
          " \"age_min\": 20, \"age_max\": 40," +
          " \"interests\": [" +
            "{\"id\":#{interest_id}, \"name\":\"#{interest_name}\"}" +
          "]" +
        "}"
    }

    response = get_response(url, params)

    response
end

def get_response(url, params)
    uri = URI.parse(url)
    uri.query = URI.encode_www_form(params)

    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    request = Net::HTTP::Get.new(uri)
    response = http.request(request)

    response.body
end


11 . Facebook sdk for api marketing. Issue with v2.9?

Answer :

Many of the objects have been renamed to remove Ad from the start of their name.

So to fix this, just change AdUser to User, and AdCampaign to Campaign.


12 . Facebook Marketing API: Tried accessing nonexisting field (X) on node type (Page)?

Answer :

The issue turned out to be as I suspected, the Systems Users tab not loading. I tried contacting Facebook and reaching out through their community help but I was unable to get a response. Ultimately, I ended up submitting the app, requesting for ads_management permissions, and then checking the System Users tab. To my surprise, the System Users tab then loaded. I don't know if the app will be approved (since I haven't built it). I am just beginning the development phase, but a "fake" submit seems to be what did the trick. This could be a total coincidence but that was my solution.


13 . Unexpected/unpredictable results with batch requests to Facebook Marketing Insights API?

Answer :

Found the issue! After looking for patterns I realised that for each campaign, a maximum of 51 dates worth of data were being fetched.

Absolutely couldn't find details about this hidden limit on the web - if anyone has any further information please add to this.


14 . Facebook Marketing API : Sharing Custom Audiences?

Answer :

I am not entirely sure what you want to do but the documentation says how you can Create and Share a custom audience with other advertiser accounts.  Reference here. You have to POST on this endpoint /{custom_audience_id}/adaccounts and specify the owner ad account and the recipient ad account. Please, check the documentation for more information. Hope this helped


15 . Facebook Marketing API - Add Users to Custom Audience?

Answer :

So this is what I did to make it work:

  • I didn't hash the data
  • I set is_raw: true
  • I cleaned up my data: Some of the emails were comming with quotes, like "john.smith@xxx.com"

Being that done, everything worked as expected.