i have set of articles on my website where people can comment using facebook.
The fix is I have to find the most commented article and show, say 5 of them, on webpage.
I have tried looking into facebook api, and googled it out for 2-3 days without having any luck.please help
You can query this info from the Facebook API - I'll explain the process to do it, but I'm not a django expert, so you'll need to turn this into Python.
Basically, you need to grab the URLs for each of your articles and hit the Graph API requesting the comments and a summary of them for that URL like this: https://graph.facebook.com/comments/?ids=YOUR-URL&summary=1
Change the YOUR-URL part of the above to the link you want to check. You can even specify more than one link at at time if you like: https://graph.facebook.com/comments/?ids=YOUR-URL1,YOUR-URL2&summary=1
So if you query the example.com comments:
Hit this URL https://graph.facebook.com/comments/?ids=http://example.com/comments&summary=1
You should get back some JSON data which looks like this (I trimmed the middle bit):
{
"http://example.com/comments": {
"comments": {
"data": [
...
],
"paging": {
"cursors": {
"after": "NDc4OQ==",
"before": "NDgyMg=="
},
"next": "https://graph.facebook.com/10150107083136229/comments?summary=1&limit=25&after=NDc4OQ\u00253D\u00253D"
},
"summary": {
"order": "ranked",
"total_count": 4822
}
}
}
}
In the "summary" section you can see there is a total_count which is the number of comments made on that URL.
So your process will be:
Loop through all the links you want to check
Hit the Facebook Graph API for that URL Extract the total_count response in the JSON and
store it (perhaps in a table)
Order the results on the number of comments descending, limiting to
only the first 5 results (if you're using MySQL then something like
SELECT * FROM whatever ORDER BY total_count DESC LIMIT 5)
Related
I am trying to use Instagram Business Discovery API to get post statistics from a certain public page.
Take Bath and Body Works (https://www.instagram.com/bathandbodyworks) for example.
GET graph.facebook.com
17895695668004550?fields=business_discovery.username(bathandbodyworks){followers_count,media_count,media{timestamp,like_count,comments_count}}
This will give me the following response:
{
"business_discovery": {
"followers_count": 3526159,
"media_count": 3536,
"media": {
"data": [
{
"timestamp": "2018-05-16T20:00:54+0000",
"like_count": 28925,
"comments_count": 530,
"id": "17917935010179826"
},
(24 posts data omitted...)
"paging": {
"cursors": {
"after": "QVFIUlBNak5fNTc3eThl..." (a very long string)
}
}
}
Now, this only gives me the most recent 25 posts, which I believe is the limit per request set by Facebook.
What should I do if I want to load the next 25 posts?
In YouTube Data API there is also a limit per request of 50, but a "nextPageToken" is provided to load the next 50 post. I assume this is the same case here?
I also found in this Facebook API document that maybe I can add a cursor string like: &after=QVFIUlBNak5fNTc3eThl...,
but this doesn't work.
Any suggestions would be appreciated, thank you!
The pagination with business_discovery is a bit different from Facebook
pagination.
There's no next and previous url's.
You need to add, after cursor as this example:
https://graph.facebook.com/v2.12/xxxx?fields=business_discovery.username(jacqehoward){id,name,username,website,profile_picture_url,biography,followers_count,media_count,media.after(QVFIUlZA5aTR5NTE4Y24tNW90VGZAPTVBtb0NpOEFPTlNLeklmVTEtUDZAfVnE0YnBhUVNOQ3BDaktzNHJBTENhTmVYLUV2SGJPZAVAxZA09hQ2NhUGdnUGFjMTNn){id,caption,comments_count,like_count,media_type,media_url,owner,timestamp}}
Note:
media.after(after_cursor){media_fields}
And if you want to paginate through business_discovery to the end you must add after cursors until there's only response with previous cursor. This is the mark that you reached the first post.
I'm completely new to Facebook Graph API.
I'm trying to use the Graph API Explorer: https://developers.facebook.com/tools/explorer/
I got the token, I'm using GET method and version 2.5 of FQL, and following is the query itself:
me?fields=id,name,picture,feed
The result from that query unfortunately only includes the id, name and picture but does not include the posts. I also tried to write "posts" instead of "feed", but the result was the same.
This is what I get:
{
"id": "123456789",
"name": "John Smith",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://fbcdn-profile-a.akamaihd.net/very-long-url"
}
}
}
As you can see, nothing about the posts.
I also tried to open a new Chrome tab and go directly to this URL:
https://graph.facebook.com/me/feed?access_token=very-long-token
And this is what I get for that:
{
"data": [
]
}
What am I doing wrong?
Any help will be profoundly appreciated!
Did you try with user_posts permission?
Maybe you forgot this...
https://developers.facebook.com/docs/graph-api/reference/v2.6/user/feed
Your app needs user_posts permission from the person who created the
post or the person tagged in the post. Then your app can read:
Timeline posts from the person who gave you the permission. The posts
that other people made on that person Timeline. The posts that other
people have tagged that person in.
Cheers
I used this URL here to get the share count of a URL
https://www.linkedin.com/countserv/count/share?url=http://google.de&format=json
{
"count": 83,
"fCnt": "83",
"fCntPlusOne": "84",
"url": "http://google.de"
}
However, when I use PHP & cURL to get the share count with the same URL, I get this
{
"count": 2285,
"fCnt": "2,285",
"fCntPlusOne": "2,286",
"url": "http://google.de"
}
When disabling cookies in the WebDeveloper addon, or using another Browser, I'm getting the correct(?) count.
When I delete the cookie lidc from the cookies of LinkedIn I get the correct count, too.
So basically, my question is, why does the share count differ? Which one is the correct one? For me, it looks like the second result is the correct one.
Referring to the Django Rest Framework tutorial app:
https://github.com/tomchristie/rest-framework-tutorial
Referring to the users page, that is:
domain/port/snippets/users/
The response is as follows, in my case:
HTTP 200 OK
Vary: Accept
Content-Type: text/html; charset=utf-8
Allow: GET, HEAD, OPTIONS
{
"count": 2,
"next": null,
"previous": null,
"results": [
{
"url": "domain/port/snippets/users/1/",
"username": "super",
"snippets": [
"domain/port/snippets/1/",
"domain/port/snippets/3/"
]
},
{
"url": "domain/port/snippets/users/2/",
"username": "super2",
"snippets": [
"domain/port/snippets/4/"
]
}
]
}
What I have been trying to do is to somehow replace the "snippets" list with a single URL that links to a page for user1_snippets in the case of the first user and to a page for user2's snippets in the case of user 2...
By "snippets list", I'm referring to this chunk of text (which could be long) : "snippets": [
"domain/port/snippets/1/",
"domain/port/snippets/3/"
]
So I just need to get the framework to produce something like the following code:
snippets
snippets
Then it will be really easy to develop the matching url conf and view.
The reason I want to do this is that in my own app, my analogous 'snippets' are very large in number, so I think it would be sensible to group them - on a separate page - for one (analogous) user. Then I can have the "user" page just for discovery of users. It will be quick to load, easy to interpret etc.
I know the answer lies in the documentation below, and I'll get there eventually but a few pointers would be really helpful.
http://django-rest-framework.org/api-guide/relations.html
Much appreciated,
There is a section on so called "Hyperlinking" in the tutorial:
http://django-rest-framework.org/tutorial/5-relationships-and-hyperlinked-apis.html
and as you said, you need to look for HyperlinkedIdentityField in the relations article.
So your serializer could look like this:
class HyperlinkedSerializer(serializers.HyperlinkedModelSerializer):
snippets = serializers.HyperlinkedIdentityField(view_name='snippet-list')
class Meta:
model = User
fields = ('snippets')
Then the url is resolved using the provided 'snippet-list' view_name.
Hope this helps.
This seems like a pretty obvious, basic thing to expect from the Graph API, but I'm having serious difficulty with it. All I want to do is get the ID for any particular URL. They have a method for this:
https://graph.facebook.com/?ids=http://www.imdb.com/title/tt0117500/
And that works great. But if I try another URL, say for my blog,
https://graph.facebook.com/?ids=http://dusda.vox.com
it doesn't give me back a numerical ID like all of the examples do. Instead, this:
{"http:\/\/dusda.vox.com":{"id":"http:\/\/dusda.vox.com"}}
If I try to use that "id", I get jack (probably because the query string looks impossible to parse):
Request: https://graph.facebook.com/http://dusda.vox.com/likes
Response: {"id":"http:\/\/dusda.vox.com\/likes"}
So what's up with this? Is the Graph API just selectively reliable, or am I misunderstanding something? I've tried it on URLs that I know are popular on Facebook, too, and I've gotten mixed results.
Try FQL for this;
http://graph.facebook.com/fql?q=select%20url%2C%20id%2C%20type%2C%20site%20from%20object_url%20where%20url%20%3D%20%22http%3A%2F%2Fkriek.hu%2F%22
returns:
{
"data": [
{
"url": "http://kriek.hu/",
"id": 497425470154,
"type": "link",
"site": "kriek.hu"
}
]
}
For more information, see object_url.
I hope it helps!
The ID is given by Facebook only to pages which have a fbshare/like button. Else the API returns the number of shares and the request URL.
If I use the facebook object debugger page I can scrape every url, for example:
https://developers.facebook.com/tools/debug/og/object?q=ddnl.de
The page give me back an url with ID and so I can get every needed parameters.
In this case https://graph.facebook.com/10150164108649475
But I don't get this ID or url with FQL or otherwise?
Very old question, but here's what I found works for me as none of the answers here really resolved my issue:
If you have a custom object tied to a url, the method suggested by Pepe only gives the id FB assigns to the url where type=link. (Which is not tied to any comments)
In my case, I need my custom object id so that I could pull associated comments from it. You can get the object id using FQL by doing a select on 'comments_fbid' from the 'link_stat' table. (This will return the object id even if no comments have been added so it should work for other cases)
api.facebook.com
At this time no of the suggested solutions work for all urls. Only the Debugger is able to get the Graph ID correctly
For example
Debugger:
https://developers.facebook.com/tools/debug/og/object?q=http%3A%2F%2Fwww.amazon.de%2Fgp%2Fproduct%2F3810510793%2F
For URL:
www.amazon.de/gp/product/3442465583/
Result:
https://graph.facebook.com/10150771435736113
{
"url": "http://www.amazon.de/dp/3810510793/ref=tsm_1_fb_lk",
"type": "book",
"title": "Die unwahrscheinliche Pilgerreise des Harold Fry: Roman",
"image": [
{
"url": "http://ecx.images-amazon.com/images/I/51I4E81xrRL._SL160_.jpg"
}
],
"description": "Die unwahrscheinliche Pilgerreise des Harold Fry: Roman",
"site_name": "Amazon.de",
"updated_time": "2012-12-19T16:54:27+0000",
"id": "10150771435736113",
"application": {
"id": "164734381262",
"name": "Amazon",
"url": "https://www.facebook.com/apps/application.php?id=164734381262"
}
}
I had the same problem here, I was trying to get the same data IMDB gets. After almost bang my head against the wall, I decided to look at the facebook's js function. And look what I get, the explanation is on the link.
Getting limited data from a page which has a Facebook ID
Peace