I want to get the total likes of a page, total comments & total likes from posts (summarized).
I'm able to get the total likes of a page with the query:
{page_id}/?fields=fan_count
But I don't know how to get the total likes & comments from all posts summarized.
I'm looking for something like:
Page ID 10202
1029 Page likes
293 Page Posts comments
2933 Page Posts likes
I know that if I execute the query:
{page_id}/posts?fields=message,likes.limit(1).summary(true)
It will return me all the posts in that page with the total likes, but I don't want to loop through all the posts to know how much likes/comments I have.
Related
I am using facebook graph api like this page_id?fields=instagram_accounts{follow_count,media_count},instagram_business_account. I am getting followers count and media count from instagram but did not get comment count and post count by weekly basis and engagement.
I am currently working on a 9gag-like site, where users submit content, and then upvote/downvote the content.
On the front page, I would like to show all articles, that were published no later that 5 days ago and have at least 2 votes. My UserArticle model has a published_at field(A DateTimeField), and I have a model called UserVote which stores the votes for the article. I have accomplished that with the following code:
def article_index(request):
time_threshold = timezone.now() - timedelta(days=5)
articles =(UserArticle.objects.annotate(num_votes=Sum('uservote__value'))
.filter(num_votes__gte=2, published_at__gte=time_threshold)
.order_by('-num_votes')
)
My only problem left is how the posts are sorted. It is currently sorted in descending order with the highest number of votes first.
In addition to being sorted by the highest number of votes, I would like to penalize older articles by the factor of days since it was published.
Something like: num_votes + age_in_days_since_publication*(-2).
Is there a way by which we can group user’s facebook likes based on the category of the pages, when I request from Graph API /[user-id]?fields=likes what I get is array of user’s likes in reverse chronological order. I need to group these likes based on the page’s category like Entertainer, Comedians, Celebrity, Artist, Actor/Director, etc categories should be grouped in a one category (say Personalities) and other pages like TV Show, Movie, TV Series, etc to be grouped in other category (let’s say Movies)
No, you would have to do any sorting on your own, after getting all the entries. You can use paging to get all entries: https://developers.facebook.com/docs/graph-api/using-graph-api/#paging
I am running an FQL query through the Facebook api:
SELECT username FROM page WHERE CONTAINS("Musician/Band")
I am expecting this to return a large amount of items, but it only returned about 100. Is there a limit on the amount of items a query like this will return? Or is this just not a query that is written wrong? In case you couldn't tell, I wanted the usernames of all of the musical artists on FB.
Thank you for your insight.
FQL has LIMIT and OFFSET keywords. You can get upto 5000 results at a time but better way to do it is through pagination
eg:
SELECT username FROM page WHERE CONTAINS("Musician/Band") LIMIT 200 //gets first 200 results
SELECT username FROM page WHERE CONTAINS("Musician/Band") LIMIT 200 OFFSET 201 //to get next 200 results
and so on..
Also you can use Facebook multiquery to minimize number of queries made.
So I'm trying to return the top 4 posts of all the posts, ranked by votes. But I don't want to return any posts that the user already has loaded on his/her page. I have an array of the post pk's the user has loaded to check. But I can't simply exclude posts the query before the slice like this
posts = Post.objects.order_by('-votes')
posts = posts.exclude(pk__in = excludePks)
posts = posts[:4]
Because then if any of the top 4 posts got excluded, I could get the 5th, 6th, 7th, or 8th top posts returned.
I'd like to only exclude posts in the top 4 if one of the pk's matches a pk in excludePks.
I tried filtering after the slice, but as I found out, that's impossible to do because a slice is equivalent to doing a LIMIT in SQL.
posts = Post.objects.order_by('-votes')[:4]
posts = posts.exclude(pk__in = excludePks)
Is there a good way to exclude posts in the top four without getting posts below the top 4 returned as a result?
Not really, but since there's only 4 and you're going to need the data afterwards anyways, filter in Python.
posts = [post for post in Post.objects.order_by('-votes')[:4]
if post.pk not in excludePks]