Facebook Marketing API Campaign spend_cap field returns inconsistently - facebook

I'm trying to pull data for each of my Ad Campaigns from the Facebook Marketing API.
In the Ads Insights API there is only a 'spend' field that returns how much of the budget for that campaign has been spent so within the specified date range parameter. This is documented at
developers.facebook.com/docs/marketing-api/insights/fields/v2.9
I would like to get the 'spend_cap' field that's specified in the Reference section of the Marketing API located in the link below. One thing I noted was that there are no parameters available to this node, that may be why the spend_cap is not returning. This is documented at
developers.facebook.com/docs/marketing-api/reference/ad-campaign-group
I am using the following url to request the data.
https://graph.facebook.com/v2.9/{act_id}/campaigns?fields=name,spend_cap&access_token={access_token}
However, it returns the spend_cap field inconsistently, as shown below. I've only included a couple examples but I'm certain that all my campaigns are set up with spending caps.
data:[
{
"id": "##############",
"name": "name1",
"start_time": "2016-06-24T14:47:34-0400",
"stop_time": "2016-07-03T14:47:34-0400"
},
{
"id": "##############",
"name": "name2",
"spend_cap": "30000",
"start_time": "2016-05-16T11:57:10-0400"
},
{
"id": "##############",
"name": "name3",
"spend_cap": "15000",
"start_time": "2016-05-16T11:44:06-0400",
"stop_time": "2017-04-01T00:00:00-0400"
},
{
"id": "##############",
"name": "name4",
"start_time": "2016-05-13T15:34:41-0400",
"stop_time": "2017-05-13T09:46:44-0400"
}
]

The spend_cap at the campaign level is an optional field which is why it is only returned for some of the campaigns.
In general within the Graph API, if a field contains no data, this field will be omitted from the response.
Our SDKs abstract this for you so you can always access a field of an object, regardless of whether it was in the response, so if you're not using one of our SDKs, you'll have to do the same.

Related

Facebook page insights lifetime metrics doesn't return results

I'm trying to get some insights on page I own, for example page_fans which is stated in https://developers.facebook.com/docs/graph-api/reference/v3.2/insights as having both "day" and "lifetime" periods. (This is NOT the only metric I want to get but for the sake of simplicity I'll give it as an example.)
Getting it by day works, but I only wa
nt to know the lifetime value, so instead of period=day I tried period=lifetime, and I get an empty data array.
This is the request I am sending:
{page_id}/insights?fields=&metric=page_fans&period=lifetime
Note, if I change to period=day I get a nice object:
"data": [
{
"name": "page_fans",
"period": "day",
"values": [
{
"value": 21578,
"end_time": "2019-02-24T08:00:00+0000"
},
{
"value": 21580,
"end_time": "2019-02-25T08:00:00+0000"
}
],
"title": "Lifetime Total Likes",
"description": "Lifetime: The total number of people who have liked your Page. (Unique Users)",
"id": "{page_id}/insights/page_fans/day"
}
],
Other metrics I want to get lifetime data for include:
"post_video_view_time_by_region_id",
"post_video_views_by_distribution_type",
"post_video_view_time_by_distribution_type",
"post_video_view_time_by_country_id"
According to the changelog for v3.2
Page Insights
These changes apply to v3.2+, and will apply to all versions on January 21, 2019.
Period parameters have been changed to day from lifetime for
the following metrics. The lifetime period parameter will return
an empty dataset.
page_fans
page_fans_city
page_fans_country
page_fans_gender_age
page_fans_locale
You can use /insights?metric=page_fans&date_preset=maximum

Facebook Graph API apprequests node doesn't return "from"

Moving from FQL to Graph API, I found that the V2.2 Graph API apprequests node returns inconsistent responses.
https://graph.facebook.com/v2.2/<id>/apprequests
sometimes returns JSON with the "from" field and sometimes not.
The correct JSON is:
"application": {
"name": "Myapp",
"namespace": "My NS",
"id": "123456"
},
"created_time": "2015-03-16T19:34:00+0000",
"data": "invite",
"from": {
"id": "111111",
"name": "Sender name"
},
"message": "Come and play!",
"to": {
"id": "99999",
"name": "Recipient"
},
"id": "123_456"
}
However, the "from" field in the JSON is sometimes missing (even when requesting it specifically in the "fields" parameter).
When using FQL, I always get the sender_uid field (with the same app token and same user):
SELECT request_id, app_id, recipient_uid, sender_uid FROM apprequest
WHERE app_id = <appID> and recipient_uid=<FBID>
Can anybody explain the mystery?
Facebook's response after investigating this bug: This is by design. There are certain privacy restrictions on Graph API which didn't apply to the deprecated FQL.
We investigated this on our end and found that this happens when the user blocked the application or completely removed Facebook's third party integration.

facebook api, is event id universally unique

The user's event data is as below. I'm wonder the id 157881474402440 is unique among all events (private, public, belong to any person) in Facebook graph since I'm intending to use it to export to a calendar system as the UID of event (I'll append it with something like "_facebook"). Tks
"events": {
"data": [
{
"name": "Return match vs Wollongong",
"start_time": "2013-08-10T14:00:00+1000",
"end_time": "2013-08-10T17:00:00+1000",
"timezone": "Australia/Sydney",
"location": "Wentworth park field 1",
"rsvp_status": "attending",
"id": "157881474402440"
}
],
Every object on facebook has unique object id. you can verify it by getting the event details from two different facebook accounts having access to the event.

Facebook Ignore Graph API Page Posts Connection - Ignore Replies & Comments? Story vs Message

I'm pulling page posts from the Graph API, but I would like to ignore comments or replies.
So for instance:
{
"id": "115673336230_10151050684306231",
"from": {
"name": "New York Jets",
"category": "Professional sports team",
"id": "115673336230"
},
"story": "\"Well said, Michael. We know our...\" on [User's name removed]'s post on New York Jets's wall.",
"story_tags": {
"40": [
{
"id": ----------,
"name": ------------,
"offset": 40,
"length": 15,
"type": "user"
}
]
},
"type": "status",
"created_time": "2012-09-27T13:39:55+0000",
"updated_time": "2012-09-27T13:39:55+0000",
"comments": {
"count": 0
}
}`
There doesn't seem to be any piece of this response that I can use to filter a reply like this out other than the 'on User's Name post' bit in the story field.
I've noticed that all of the replies to comments appear without message data and with story data, but from the docs its unclear if this would be a reliable data point to filter against.
Is there a way to ignore comments/replies in the Page posts connection? Do all Page Posts (non comment replies) have data in the message field and never in the story field? That is, can I reliably ignore 'posts' that have no message? That have a story?
If you want more powerful filtering, you should look at querying the stream table with FQL.
The type field allows you to filter out posts based on what they are. Adding AND type != 247 will exclude comments from the data returned.
There might be a way to do this using the API by requesting the status_type field, but then you'll have to also manually request all other fields you want to display, and you'll still end up filtering them in your script.

Determining which fields and connections are returned in a FB.api query

When I query Facebook via FB.api with the following:
me/events
A JSON event array in the returned JSON object has information for the fields "name", "start_tile", "end_time", "location", "id", and "rsvp_status". I know I can obtain information on additional fields and connections (such as the "picture" connection or the "owner" field) by parsing the "id" field and querying the individual event directly but is there a way to request this information in the initial query so I can avoid the extra FB.api calls?
{
"name": "Example Name",
"start_time": "2012-05-04T22:00:00",
"end_time": "2012-05-05T01:00:00",
"location": "Example Location",
"id": "xxxxxxxxxxxx",
"rsvp_status": "attending"
}
From https://developers.facebook.com/docs/reference/api/
Introspection
The Graph API supports introspection of objects, which enables you to
see all of the connections an object has without knowing its type
ahead of time. To get this information, add metadata=1 to the object
URL, and the resulting JSON will include a metadata property that
lists all the supported connections for the given object. For example,
you can see all the connections for the Developer Garage event above
by fetching https://graph.facebook.com/331218348435?metadata=1. That
outputs:
{
"name": "Facebook Developer Garage Austin - SXSW Edition",
"metadata": {
"connections": {
"feed": "https://graph.facebook.com/331218348435/feed",
"picture": "https://graph.facebook.com/331218348435/picture",
"invited": "https://graph.facebook.com/331218348435/invited",
"attending": "https://graph.facebook.com/331218348435/attending",
"maybe": "https://graph.facebook.com/331218348435/maybe",
"noreply": "https://graph.facebook.com/331218348435/noreply",
"declined": "https://graph.facebook.com/331218348435/declined"
}
}
}