For over a week I'm trying to get the share count for a specific user post (that post has been directly shared by a friend).
All permissions are ok (read_stream included).
I've tried using the Graph API or via the FQL, all I can get is the comment count and the like count (share count doesn't even appear in the json response).
Is there something new to take into account to obtain that information?
Any help would be really appreciated.
Thanks in advance.
I am assuming you must be having the post id. So you can simply use the API-
/{post-id}?fields=shares
you'll get the response as-
{
"shares": {
"count": 999
},
"id": "POST_ID",
"created_time": "XXXX-XX-XX"
}
Demo
use ajax call to obtain the result
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script>
function setcount(id,urlForLike){
$.ajax({
url: urlForLike,
success: function(data){
// console.log(data[0].like_count);
$("#img-"+id).append(data[0].like_count);
}
});
}
then call the function from where you want the result
<script>
setcount("<?php echo 'SOMETHING UNIQUE';?>","<?php echo 'https://api.facebook.com/method/links.getStats?urls='YOUR URL");
</script>
then place this code to display the share count
<span id="img-<?php echo 'SOMETHING UNIQUE'; ?>">
wherever there is 'SOMETHING UNIQUE' change this to id of the post or number to append the data to the div/span. ALso change 'YOUR URL' to the url of the page/link whichever suits your need.
[{"url":"URL","normalized_url":"URL","share_count":4,"like_count":197,"comment_count":15,"total_count":216,"click_count":0,"comments_fbid":null,"commentsbox_count":0}]
above json data is how the output of the ajax call
Related
I want to get likes on post on the page: "The Jungle Book"
I am able to get the likes of the page using url:
https://graph.facebook.com/" + pageId + "?fields=likes&access_token=" + ACCESS_TOKEN
I have read the documentation
and find that i will get the likes(total count) of the post only returned when the flag summary=true is set
The response should look like this
{
"likes": <somecount>,
"id": "151505938209071_1507814655911519"
}
I am able to get the likes on page but not able to get total number of likes on the particular post on that page.
Can anyone help me regarding how I should set the URL or is there any other way to do it.
From what you described it sounds like it should be like this:
https://graph.facebook.com/" + pageId + "?fields=likes&summary=true&access_token=" + ACCESS_TOKEN
The above is your existing URL with summary=true in between the fields=likes and access_token parameters
However you may be interested in this answer
Quote:
Couldn't find this in the documentation but multiple calls to the API are not necessary. You can use summary when querying a feed or multiple posts. Specify this in the fields parameter.
https://graph.facebook.com/PAGE_ID/feed?fields=comments.limit(1).summary(true),likes.limit(1).summary(true)
This will return a response like this.
{
"data": [
{
....
"summary": {
"total_count": 56
}
...
},
{
....
"summary": {
"total_count": 88
}
...
}
]
}
This will be much faster than making individual requests for each object just to get the number of comments or likes.
There is the question about fetching count of user friends via FaceBook API.
I want to get the number of friends only have USER_ID of the any facebook user. As I know I can get it using FQL like:
SELECT friend_count FROM user WHERE uid = X
But for some users this value is null or there is no value. Please advice is there another way to get this value?
That user might be keeping that information private. In that case, you cannot fetch that information.
You just check the following link. You need to generate token (by clicking on Get Token you will get it) with data you want from facebook API, need to select friends option to get the friend count.
https://developers.facebook.com/tools/explorer/?method=GET&path=me%3Ffields%3Did%2Cname%2Cfriends&version=v2.8
FB.api(
'/me',
'GET',
{"fields":"id,name,friends,link,email,gender,picture,first_name,last_name,cover"},
function(response) {
// Insert your code here
}
);
after executing this you will get this in response as
{
"id": "XXXXXXXXXX",
"name": "Test test",
"friends": {
"data": [
],
"summary": {
"total_count": 14
}
}
}
total_count will be your friend count
I have written a code to get all album names to list it. When i write code using javascript
it returned me an empty set.
FB.api('/me/albums', function(response) {
});
I tried Query also . It also returned me an empty set
SELECT aid,owner,name FROM album WHERE owner = me().
I am having album in my account but still it is returning empty set. Please help me in figuring out
include access_token in parameters list
FB.api('/me/albums?access_token=' + accessToken, function(response) { });
Make sure that the user has authorized the app and supply the access token with the query;
FB.api('/me/albums?access_token=ACCESS_TOKEN', function(response)
{
console.log(response);
});
I have made sure that the user has 'read_insights' permission. I also have 'manage_pages' permission. I receive no errors which is kind of annoying as it woud help.
All I ever get is an empty array. The Graph API works just fine, returning correct data every time.
FQL does not work, and I have never got Insights from it yet. Either they have a bug or I'm doing something wrong.
I have this code to get some Insights:
$('.page-entry>a').live('click', function(e) {
e.preventDefault();
var id = $(this).parent().attr('id');
FB.api(
{
access_token: accessToken,
method: 'fql.query',
query: 'SELECT metric, value FROM insights WHERE object_id = ' + id + ' AND metric="page_impressions" AND end_time=end_time_date("2012-06-01T07:00:00+0000") AND period=period("month")'
},
function(data) {
console.log(data);
}
);
})
The user is logged in, and I can see all of their pages/apps fine. I have the id's and even access_tokens for each page. I tried that for FQL, it didn't work.
Any help appreciated.
I am trying to get the JSON for the following soundcloud track listing page.
http://soundcloud.com/tags/Hiphop
The query I try to perform is
http://api.soundcloud.com/tracks.json?order=hotness&limit=20&created_at[from]=2012-05-18&tags=hiphop + consumer key.
All of the songs on that tags page are less than 3 days old, and I am ordering by hotness. The filters doesn't seem to work at all. The results of the query and the tags/Hiphop page are not even close. Am I missing something?
Unfortunately the created_at filter cannot be used with the order parameter. If you'd like to replicate the listing in the URL you provided, just make the following API request:
https://api.soundcloud.com/tracks.json?client_id=YOUR_CLIENT_ID&tags=hiphop&order=hotness
Or, in JavaScript, assuming you have a ul element with an id 'tracks':
var url = 'https://api.soundcloud.com/tracks.json?client_id=YOUR_CLIENT_ID&tags=Hiphop&order_by=hotness';
$.getJSON(url, function(data) {
$.each(data, function(index, track) {
$('<li />', { text: track.title }).appendTo('#tracks');
});
});