I am using facebook graph api where I periodically call: https://graph.facebook.com/cnn/posts?access_token=accesstoken
I don't want to get repeat posts the second time I make the call so I would like to filter the call to get anything after either a certain post Id or after a created_time. Is this possible?
I have tried using date_range= but it did not work plus it only allowed me to search by date but not time.
Use timebased paging: https://developers.facebook.com/docs/graph-api/using-graph-api/#paging
The correct parameter would be since and until. Just store the timestamp of the last post and use it in your next call.
Related
I am trying to get the summary from multiple campaigns from the facebook graph api. I already managed to get a filtered view, so i just get the Campaigns i need:
I am able to get the reach and impression data by platform for every Campaign, but if i sum it up, its not the same result as marked in the screenshot.
https://graph.facebook.com/v14.0/act_BUSINESS_ID/campaigns?fields=name,id,status,objective,insights{impressions}&filtering=[{field: "id",operator:"IN", value: ['CAMPAIGN_ID1"','CAMPAIGN_ID2"']}]
Is it possible to get the reach and impression Data as a summary and breakdowned by platform like in the Screenshot?
So, finally i got the right way!
The call should look like this:
act_Accunt_id/insights?breakdowns=publisher_platform&fields=ad_id,clicks,unique_clicks,cpm,impressions,reach,spend&default_summary=true&date_preset=maximum&filtering=[{field: "campaign.id",operator:"IN", value: ['ID1','ID2']},{"field":"publisher_platform","operator":"CONTAIN","value":"facebook"}]
I just came up with also filtering by publisher_platform and thats it!
You can filter any campaign field and as long, as you set the default_summary and the date_preset values correctly, the numbers are exact.
Get data for a specified date.
https://graph.facebook.com/v5.0/campaigns_id?fields=id,name,delivery_status,effective_status,status,spent,daily_budget,frequency,result,insights.time_range({'since':'2020-02-20','until':'2020-02-20'}){impressions,inline_link_clicks,cost_per_inline_link_click,cpm,inline_link_click_ctr}&access_token=XXXXX&time_range({'since':'2020-02-20','until':'2020-02-20'})
I get data for all the time.
How can I get data for a specified date ?
Time ranges can only be applied to "insights" edge here
You can achieve this with this call:
https://graph.facebook.com/v5.0/{your-campaign-id}?fields=id,name,effective_status,status,daily_budget,insights.time_range({'since':'2020-02-20','until':'2020-02-20'}){impressions,inline_link_clicks,cost_per_inline_link_click,cpm,inline_link_click_ctr}&access_token=XXXXX
You only need your first "time_range" in your query
I am working with Facebook graph api for few days. I am trying to extract user's status and the information of reshared if any. I can easily find status of a user using fields=id,name,statuses query. But I could not find any information about re-sharing. I found a field of status sharedposts. But could not understand what it actually does. Can anyone enlighten me about how can I collect information about resharing (who reshared,when reshared,resharing location). I used user_status access token.
The sharedposts field applies to a status id. For example, the status id 10151794781777494 is from a status update by the TheKrazyCouponLady which has been shared 4 times. This query:
/10151794781777494?fields=sharedposts
Will return all the information about the users that have shared it. If you want to limit the returned fields to the name and id of the sharer, and the time and location it was shared, you could do this:
/10151794781777494?fields=sharedposts.fields(from,created_time,place)
Although I expect there won't be any location data most of the time.
To find the status id in the first place, you could just query the statuses field for a particular user. Again, using TheKrazyCouponLady (uid 255919387493) as an example:
/255919387493?fields=statuses
To get just the ids:
/255919387493?fields=statuses.fields(id)
As an alternative to that, you may want to consider querying the user's posts instead. The advantage to using posts, is that you can get back the share count for each post in that query.
/255919387493?fields=posts.fields(id,shares)
If the share count on a post is zero, then there is obviously no need to run another query to retrieve the users that have shared that post.
The downside of using posts is that the post id is slightly different from a status id. You'll see ids that look like this:
255919387493_10151794781777494
The first half of that string is the user id of the post owner. The second half is the actual status id. If you want to query the sharedposts field for the post, you first have to extract the second half (the status id) and use that for the query.
Having said that, it occurs to me that you could actually retrieve all the information you need in one go if you chain the statuses query and the sharedposts query together. For example, something like this:
/255919387493?fields=statuses.fields(id,message,sharedposts.fields(from,created_time,place))
That will return the status id and message text for each status from that user, and the user details, create time and location for each person that shared each of those statuses.
Even with paging, though, that is likely to be a fairly slow query, so I'm not sure if that's such a good idea. It's worth considering though.
According new version of API 2.1 and documentation from here
https://developers.facebook.com/docs/graph-api/reference/v2.1/post
there is a new edge called "sharedposts"
As described here https://developers.facebook.com/docs/graph-api/reference/v2.1/object/sharedposts
This reference describes the /sharedposts edge that is common to
multiple Graph API nodes. The structure and operations are the same
for each node.
This edge represents any posts where the original object was shared on
Facebook.
If the post type is photo sharedposts will return empty as the object is different to the postID
/317380948302131_847979698575584 => Object : 847979378575616
/317380948302131_847979698575584/sharedposts?fields=from,via
ObjectID will work as expected
/847979378575616//sharedposts?fields=from,via
The only problem if the object is a shared_post it will show all shares from the original post object too and no via node is present .
Just struggle around some time why the APi only sometimes return sharedposts
Using the Graph API or FQL, is there a way to efficiently find a user's first post or status? As in, the first one they ever made?
The slow way, I assume, would be to paginate through the feed, but for users like me who joined in 2005 or earlier, that would take a very long time with a huge amount of API calls.
From what I have found, we cannot obtain the date the user registered with Facebook for a good starting point, and we cannot sort by date ascending (not outside of the single page of data returned) to get the oldest post on top.
Is there any reasonable way to do this?
you can use facebook query language (FQL) to get first post information.
Please refer below query for more details :-
SELECT message, time FROM status WHERE uid= me() ORDER BY time ASC LIMIT 1
Please check and let me know in case of any issue.
Thanks and Regards
Durgaprasad
I think the Public API is limited to the depth of information it is allowed to query. Facebook probably put in these constraints for performance and cost concerns. Maybe they've changed it. When I tried to go backwards thru a person's stream about 4 months ago, there seemed to be a limit as to how far back I could go. Maybe it's a time limit or a # posts back limit. If you know when your user first posted, then getting to it should be fairly quick using the since/until time stamps in your queries.
I currently have a .NET method that looks like this - GetUsers(Filter filter) and this is invoked from the client by sending a SOAP request. As you can probably guess, it takes a bunch of filters and returns a list of users that match those filters. The filters aren't too complicated, they're basically just a set of from date, to date, age, sex etc. and the set of filters I have at any point is static.
I was wondering what the RESTful way of doing this was. I'm guessing I'll have a Users resource. Will it be something like GET /Users?fromDate=11-1-2011&toDate=11-2-2011&age=&sex=M ? Is there a way to pass it a Filter without having to convert it into individual attributes?
I'm consuming this service from a mobile client, so I think the overhead of an extra request that actually creates a filter: POST filters is bad UX. Even if we do this, what does POST filters even mean? Is that supposed to create a filter record in the database? How would the server keep track of the filter that was just created if my sequence of requests is as follows?
POST /filters -- returns a filter
{
"from-date" : "11-1-2011",
"to-date" : "11-2-2011",
"age" : "",
"sex" : "M"
}
GET /Users?filter=filter_id
Apologies if the request came off as being a little confused. I am.
Thanks,
Teja
We are doing it just like you had it
GET /Users?fromDate=11-1-2011&toDate=11-2-2011&age=&sex=M
We have 9 querystring values.
I don't see any problem with that
The way I handle it is I do a POST with the body containing the parameters and then I return a redirect to a GET. What the GET URL looks like is completely up to the server. If you want to convert the filter into separate query params you can, or if you want to persist a filter and then add a query param that points to the saved filter that's ok too. The advantage is that you can change your mind at any time and the client doesn't care.
Also, because you are doing a GET you can take advantage of caching which should more than make up for doing the extra retquest.