Get Facebook event content_name in API call - facebook-graph-api

As per Facebook's documentation it is possible to send additional object properties when tracking an event as per the following example;
fbq(
'track', 'Lead', {
content_name: 'Auto Insurance',
content_category: 'Quote',
value: 40.00,
currency: 'USD'
}
);
I am able to get the number of leads with the following endpoint:
https://graph.facebook.com/v13.0/act_XXXXX/insights?access_token=XXXXX&date_preset=this_year&fields=account_name,campaign_name,conversions,actions&level=campaign
But is it possible to get the number of Leads grouped by content_name. I can't find the documentation anywhere.

Related

API Graph Instagram, Insights, get count likes for user

I want to get the total of like for a user profile, to do this I'm using this endpoint : https://developers.facebook.com/docs/instagram-api/reference/ig-user/insights#lecture:~:text=GET%20/%7Big%2Duser%2Did%7D/insights
I know this metrics is not available in the documentation but when I call the endpoint with a bad metric, the reponse show metrics available and here is the response:
"message": "(#100) metric[0] must be one of the following values: impressions, reach, follower_count,
email_contacts, phone_call_clicks, text_message_clicks, get_directions_clicks, website_clicks,
profile_views, audience_gender_age, audience_locale, audience_country, audience_city, online_followers,
accounts_engaged, total_interactions, likes, comments, shares, saved, replies, engaged_audience_demographics,
reached_audience_demographics, follower_demographics, follows_and_unfollows, profile_links_taps"
https://graph.facebook.com/{ig-user-id}/insights?access_token={access-token}&metric=bad&period=lifetime
As you can see likes is available.
So when I call the endpoint with the metric likes, I get a new error:
"message": "(#100) The following metrics (likes) should be specified with parameter metric_type=total_value"
https://graph.facebook.com/{ig-user-id}/insights?access_token={access-token}&metric=likes&period=lifetime
Then I add the parameter metric_type with value total_value, and I get a new error:
"message": "(#100) Param metric_type on field insights: This param is not valid"
https://graph.facebook.com/{ig-user-id}/insights?access_token={access-token}&metric=likes&period=lifetime&metric_type=total_value
If someone know what i'm doing wrong, it will be a pleasure to get the solution.
Thank's for your responses !

Instagram Graph API - Fetch media insights metric when a user switched from personal to business account

I'm looking for a way to fetch Media Insights metrics in Instagram Graph API (https://developers.facebook.com/docs/instagram-api/reference/media/insights) with a nested query based on the userId, even when a client switched from a Personal to a Business account.
I use this nested query to fetch all the data I need : https://graph.facebook.com/v3.2/{userId}?fields=followers_count,media{media_type,caption,timestamp,like_count,insights.metric(reach, impressions)} (this part causes the error: insights.metric(reach, impressions) - it works however for an account that has always been a Business one)
However, because some media linked to the userId were posted before the user switched to a Business account, instead of returning the data only for the media posted after, the API returns this error:
{
"error": {
"message": "Invalid parameter",
"type": "OAuthException",
"code": 100,
"error_data": {
"blame_field_specs": [
[
""
]
]
},
"error_subcode": 2108006,
"is_transient": false,
"error_user_title": "Media Posted Before Business Account Conversion",
"error_user_msg": "The media was posted before the most recent time that the user's account was converted to a business account from a personal account.",
"fbtrace_id": "Gs85pUz14JC"
}
}
Is there a way to know, thru the API, which media were created before and after the account switch from Personal to Business? Or is there a way to fetch the date on which the account was switched?
The only way I currently see to get the data I need is to use the /media edge and query insights for each media until I get an error. Then I would get approximately the date I need. However, this is not optimized at all since we are rate limited to 200 calls per user per hour.
I have the same problem.
For now, I'm Switch between queries (if first have error)
"userId"?fields=id,media.limit(100){insights.metric(reach, impressions)}
"userId"?fields=id,media.limit(100)
I show the user all insights in zero.
I don't know if they're the best alternative, like identify the time of conversion to business and get the post between this range of DateTime
I got the same problem and solved it like this:
Use the nested query just like you did, including insights.metric
If the error appears, do another call without insights.metric - to at least get all other data
For most accounts, it works and there is no additional API call. For the rest, i just cannot get the insights and i have to live with it, i guess - until Facebook/IG fixes the issue.
I got the same problem and solved it like this:
Step1: Convert your Instagram account to a Professional account.
Step2: Then According to Error Post a new post on Instagram and get their Post-ID.
Step3: Then try to get a request using that Post-ID.
{Post-ID}?fields=comments_count,like_count,timestamp,insights.metric(reach,impressions)
curl -i -X GET "https://graph.facebook.com/v12.0/{Post-ID}?fields=comments_count%2Clike_count%2Ctimestamp%2Cinsights.metric(reach%2Cimpressions)&access_token={access_token}"
For more: insights
Here is the relevant logic from a script that can handle this error while still doing a full import. It works by reducing the requested limit to 1 once the error is encountered. It will keep requesting insights until it encounters the error again, then removes insights from the fields and returns to the requested limit.
limit = 50
error_2108006 = False
metrics = 'insights.metric%28impressions%29%2C' # Must be URL encoded for replacement
url = '/PAGE_ID/media?fields=%sid,caption,media_url,media_type&limit=%s' % (metrics, limit)
# While we have more pages
while True:
# Make your API call to Instagram
posts = get_posts_from_instagram(url)
# Check for error 2108006
if posts == 2108006:
# First time getting this error, keep trying to get insights but one by one
if error_2108006 is False:
error_2108006 = True
url = url.replace('limit={}'.format(limit), 'limit=1')
continue
# Not the first time. Strip out insights and return to desired limit.
url = url.replace(metrics, '')
url = url.replace('limit=1', 'limit='.format(limit))
continue
# Do something with the data
for post in posts:
continue
# If there are more pages, fetch the next URL
if 'paging' in posts and 'next' in posts['paging']:
url = posts['paging']['next']
continue
# Done
break

Sharing multiple images/photos through the FB share opengraph function

Is it not possible to share multiple images through the Facebook share opengraph function?
The code snippet reads like this:-
FB.ui({
method: 'share_open_graph',
action_type: 'og.likes',
action_properties: JSON.stringify({
object: {
'og:url': xxx,
'og:title': xxxxx,
'og:description': xxxx,
'og:image': img_arr
}
})
}, function (response) {
// callback function goes here… });
It is required for img_arr to be an image array. But the dialog box shows up blank saying that “Sorry, something went wrong.
We're working on getting this fixed as soon as we can”. The images being shared on the facebook post is dynamic.
Facebook no longer allows the overrides. You must have the og metadata in the head.

Facebook Webhooks. How to create an event that will work on like and unlike?

How to create an event that will work on like and unlike?,
when I create a webhook
object = page callback_url = ”example.com" fields = feed verify_token =
hub_verify_token
verification callback_url passes and the answer is tapped
{ “success”: true }
But after like or unlike on callback_url nothing is sent.
The events that I have used before :
edge.create and edge.remove.
http://i.imgur.com/xK5C4IK.png
Help please!
There is a solution to the problem:
Details here: https://developers.facebook.com/docs/graph-api/reference/page/subscribed_apps/
Code example in the JavaScript SDK:
/* make the API call */
FB.api(
"/{page-id}/subscribed_apps",
'POST',
{
"object":"page",
"callback_url":"https://example.com/callback",
"fields":"likes",
"verify_token":"my_token_code",
"access_token" : "you_access_token"
}
function (response) {
if (response && !response.error) {
/* handle the result */
}
}
);
but unlike for the page does not work (((
what do you think about it?
There is a list of all webhook fields in the docs: https://developers.facebook.com/docs/graph-api/webhooks/reference/page/
There is no specific webhook about likes/unlikes. According to this article, it should be possible though: https://developers.facebook.com/blog/post/2017/11/07/changes-developer-offerings/
The feed hook may only deliver likes to posts:
Describes nearly all changes to a page's feed, such as posts, shares,
likes, etc. The values received depend on the types of changes made to
the page's feed.

Can't subscribe to page's likes through Real-time updates API

I am trying to get updates when the like count of a page my app is on is updated. I am trying to accomplish this by using the FB Real-time Updates API
When I do a POST, with the object = "page" and the fields = "likes", I get a 400 error with the message '"likes" is an invalid field name'.
object = "page" and the fields = "name" works fine.
The documentation states you are allowed to subscribe to any public attribute.
For those playing the home game, here are the steps to reproduce the problem:
Get an OAuth token for your app:
https://graph.facebook.com/oauth/access_token?client_id=<app_id>&client_secret=<secret>&grant_type=client_credentials
Post to subscription URL:
https://graph.facebook.com/<app_id>/subscriptions
POST Variables:
'access_token' => `<access token from step 1>`,
'object' => 'page',
'fields' => 'likes',
'callback_url' => `<a callback url>`,
'verify_token' => 'testingstring123'
This isn't supported - from the section 'Real-time Updates' on https://developers.facebook.com/docs/reference/api/page/ :
The Page object supports Real-time Updates for picture, tagged and
checkins connections.
Note: Real-time updates are not yet supported for the total number of
Page checkins.
Subscribing to likes is only for pages that a user likes. The 'likes' object is what pages a user or page likes, not the count of how many people like your page, which cannot be subscribed to.