V11.0 Facebook Graph API - since / until not populating entire date range - facebook

I'm doing the following request in the Facebook Graph API explorer:
url = f'https://graph.facebook.com/{page_id}/posts?since=2021-02-02&until=2021-02-10&
fields=id,created_time, from,shares,comments.limit(0).summary(true),
insights.metric(post_impressions_paid,post_impressions_paid_unique).period(lifetime),
attachments{title, unshimmed_url}&access_token={page_access_token}'
but when I look at the created_time it only shows from "created_time":"2021-02-06T20:00:13+0000" to "created_time":"2021-02-09T23:30:04+0000"

Related

How to get Instagram post URL from Facebook Graph media_id

I'm using Instagram Mentions API and was able to obtain FB media_id for couple Instagram posts.
I need media_id to get post content via /user/mentioned_media. Unfortunately that endpoint does not provide ig_id or shortcode or permalink which I need.
Is there a way to get Instagram Post URL with FB Graph API media_id?
It seems like you can get media metadata (and all comments/replies) when someone #-mentions you in a non-owned-media comment by using a query like below.
You would use your own instagram business account id for the first number (the path component), and you'd use the comment_id you received from the webhook comment-mention notification as the second number:
/12345678901234567890?fields=mentioned_comment.comment_id(9876543210987654321){id,text,username,timestamp,media{id,media_type,media_url,permalink,username,like_count,comments_count,comments{id,text,username,user{id,username},like_count,timestamp,replies{id,text,username,user{id,username},like_count,timestamp}}}}
Yes, there is a way you can get Instagram post URL associated with a media if you know the media id.
You can also get more information (all its fields and edges) on media. See the docs here
You can get the Instagram post URL by making a GET request to /{ig-media-id}
Sample Request:
GET https://graph.facebook.com/v15.0/{{media_id}}?fields=permalink, shortcode&access_token={{ACCESS_TOKEN}}
Sample Response:
{
"permalink": "https://www.instagram.com/p/Clxsi5Pol2_/",
"shortcode": "Clxsi5Pol2_",
"id": "17xxx59557977xxx"
}
The value of the permalink is the valid public URL for the post.
You can also use the shortcode returned to construct the URL by concatenating the shortcode to https://www.instagram.com/p/.

Identifying a Facebook user id from a url?

I've been playing around with the Facebook graphs api for a while, and to the best of my knowledge you shouldn't be able to get a Facebook user's id from their username.
I then came accross stalkscan.com and note that they do just that. You provide a Facebook url and the resulting queries contain that usernames profile id.
How can I acheive a similar result with or without the graphs api?
You can get a facebook user id by using the following endpoint:
URL /?id={url}
{url} represents an external URL as it relates to the Facebook social graph - shares and comments from the URL on Facebook, and any Open Graph objects associated with the URL. (e.g. a user, a page...).
With Python, you can use something like this:
import requests
USER_URL = '' # your link
ACCESS_TOKEN = '' # your credentials
params= {'id': USER_URL,'access_token': ACCESS_TOKEN}
fb_graph = "https://graph.facebook.com/v2.7/"
r = requests.get(fb_graph, params=params)
fb_id = r.json().get('id')
print('Facebook User ID: %s' % fb_id)
Full documentation of the graph API is available here.

How to get "news main stream" from the main facebook site?

How to get the general information listed on the home page?
Facebook makes a request to
https://www.facebook.com/ajax/pagelet/generic.php/LitestandMoreStoriesPagelet?
with params:
ajaxpipe
ajaxpipe_token
no_script_path
data
__user
__a 1
__dyn
__req
__rev
__adt
And although it returns a json (inside a script with conditions...) is not a clean answer.
Is there another way to get that data? I do not want to use the sdk.
If you want the 'News feed', you'll want to use the /user/home/ API endpoint:
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/home
e.g. https://graph.facebook.com/me/home?access_token=VALID_ACCESS_TOKEN will just grab your own News Feed.
You can also filter by any of the 'filter_key' values returned from the FQL query (use the Graph API Explorer and API version 2.0):
SELECT filter_key, name, type, value FROM stream_filter WHERE uid = me()
e.g. adding the query string filter=app_2305272732 will return a feed of things from the 'Photos' app (i.e. photos added to Facebook by your friends)

Facebook public objects not retrievable through Graph API or FQL

I am searching the public feed and once I get the objects I want to get more information on them. I login with an auth token and when I try to get more information through both the graph API and FQL I get the following results.
Graph API - I run the following request "https://graph.facebook.com/{pid or object_id}"
Results - I get the error "Unsupported get request."
FQL query - I run something like "Select {fields} from photo where pid = '{pid}'"
Document - "To read the photo table you need any valid access_token if it is public and owned by the Page."
Results - I get an empty data array.
This used to work and I am not sure if I am doing something wrong or this functionality has changed?
Thank you for any insight you might have,
Stefanie
Facebook says this is "By Design" via developers.facebook.com/bugs/285682524881107

using facebook graph API vs FQL insights

I'm trying to get insights from facebook for some pages I have admin rights to. I'm able to get the correct data with the graph API but when I try with FQL I get an empty JSON object. Any idea what the problem may be?
I think the query is correct because I do not get any 400/500 errors. I also think the permissions are correct because I'm using the same framwork with the graph API solution and it works fine. Maybe you need additional permissions to use FQL? I have manage_pages and read_insights.
I'm implementing with basic text replacement on the template URIs from facebook's documentation.
EDIT: I think the problem may be that I don't actually have the read_insights permission. I do have the manage_pages permission. Perhaps this explains why I can access insights through Graph API but not FQL?
Graph API query:
string insight_str = "https://graph.facebook.com/APP_ID/insights/FIELD/FREQ?access_token=ACCESS_TOKEN";
string url = insight_str.Replace("FIELD", "page_impressions").Replace("FREQ","day").Replace("APP_ID", accounts[i].id).Replace("ACCESS_TOKEN", accounts[i].access_token);
https://graph.facebook.com/xxxxxxxx/insights/page_impressions/day?access_token=xxxxxxxx
Graph API parsed JSON result:
page_impressions
2011-12-28 412
2011-12-29 971
2011-12-30 373
FQL query:
string query_str = "https://graph.facebook.com/fql?q=QUERY&access_token=ACCESS_TOKEN";
string query = "SELECT+metric,value+FROM+insights+WHERE+object_id=APP_ID+AND+metric='FIELD'+AND+end_time=1322722800+AND+period=86400";
string url = query_str.Replace("QUERY",query).Replace("FIELD","page_impressions").Replace("APP_ID",accounts[i].id).Replace("ACCESS_TOKEN",accounts[i].access_token);
https://graph.facebook.com/fql?q=SELECT+metric,value+FROM+insights+WHERE+object_id=xxxxxxxx+AND+metric='page_impressions'+AND+end_time=1322722800+AND+period=86400&access_token=xxxxxxxx
FQL JSON result:
{"data":[]}
I have the same problem with Facebook C# SDK version 5.4.1 and 5.3.2 (see my post Error with FQL query with library 5.4.1)
I always receive an empty response like you.
You must have the read_insights permission.
I think the end time in your example is slightly off. It needs to fall exactly at midnight PST. I obtained a value once I moved the time forward an hour, to 1322726400.