I tried with graph api explorer to get user count. It work perfectly.
But how to get the total post count using API.
Is there any way to get the user count and post count of a a user using userId?
There is no field or endpoint to get a user’s post count.
(Getting the user’s permission to read their posts, and then paginate through all of them & do the count yourself, might sound possible in theory, but in reality that probably won’t work. You’ll run into the API request limits quickly, plus there’s likely always gonna be some posts your app can’t “see” because of some obscure constellation of privacy settings. Also, from my experience, the API tends to get kinda unreliable, the further you try to go back in time.)
Related
I need to quickly get the names of about 1000 users that I now only have the facebook id and access tokens of. I'm not comfortable with the FB api yet so I was considering just writing a scraper to retrive the name from the FB page of the user (since I have the id of the users).
Is this allowed? I assume it's not "best practice" but how severe is it? Will it get me banned for instance? The data will only be used to complete our user database so no advertisement
Alternativly: Can anyone point me in to a good (and up to date) guide of how to get user info using the FB api (keep in mind that I have the ID and the access.tokens of all my users).
No, scraping is not allowed and you MUST use the Graph API: https://www.facebook.com/apps/site_scraping_tos_terms.php
/me?fields=name&access_token=[user-access-token] returns the name of a User - You may run into API limits though, but if it´s a one time thing it should not really matter. If you run into limits, just wait a bit and get the next batch.
I know one solution would be to retrieve the IDs of places located in a specific location using the Facebook Graph API, to retrieve the IDs of all the Facebook pages liked by my friends and then to pick only the IDs of pages in the location that my friends liked (using the "social context" that enables me to know how many friends liked a page). But it doesn't sound like the best solution to me (it represents LOTS of data).
Another solution could be to imply dependencies between operations in the request using the JSONPath expression format (https://developers.facebook.com/docs/graph-api/making-multiple-requests/) but as said in the documentation "for security reasons filter and script JSONPath constructs are not allowed in the JSONPath expression", which limits significantly the usefulness of this strategy.
So I tried to use Batch Requests:
curl \
-F 'access_token=...' \
-F 'batch=[{"method":"GET", "name":"likes-ids", "relative_url":"me/friends?fields=likes{id}"}, {"method":"GET", "relative_url":"search?type=place¢er=48.85,2.35&distance=1000&ids={result=likes-ids:$.data.*.likes.data.*.id}"}]'
There are 2 issues in each batch request:
Weirdly enough, "me/friends?fields=likes{id}" gets me some likes of
some of my friends (I think it's possible to get all the likes of
all my friends as friends_likes has been deprecated, correct me if
I'm wrong)
Even for the user's friends' likes I manage to
retrieve, I don't get anything from the second batch request.
NB: The user's friends shouldn't need to login on my app (meaning I don't have the user_likes permission for them).
I'd be grateful if anyone could help with some remarks or ideas.
You need the friend to grant the user_likes. You are probably using the Graph API Explorer so your friends might have been testing and granted the user_likes permission (thus why you see some and not all)
A user access token with user_likes permission is required to see all pages liked by that person.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/likes
Notice it doesn't say friends.
For the second part, are you sure the ids returned from the first part of the batch have ids for places? For each friend object, only 25 likes are returned, you aren't guaranteed that the likes you get are pages of type place.
Also search?type=place¢er=48.85,2.35&distance=1000&ids=, I don't this does what you think it's supposed to do. ids seems to override the type,center and distance.
e.g. search?type=place¢er=48.85,2.35&distance=1000&ids=375093055847509
is the same as
search?ids=375093055847509
Seems like a bug here or an intended behaviour that as along as ids is returned override every other parameter.
So overall no, this batch call will work, the results you are returning are incorrect for your desired outcome.
So the only way is indeed the initial plan you had but in any event the query will only work for friends who are using your app.
https://developers.facebook.com/docs/graph-api/reference/v2.2/page.context/friends_who_like
Only friends who use the requesting app will be returned.
I want to get all fans basic data who likes my Facebook page. I have post a request to this URL(https://www.facebook.com/plugins/fan.php?connections=100&id=XXXXXXXXX) and i am getting response as 100 fans at a time randomly. I need all the fans at once or else 100 unique members at a time but not random. Is there any chance to get all 53k fans at a time. Can we use Graph API for this. Please help me.
Thanks,
Neer.
Sadly, there's no way you can access the list of your 53,000 fans through Graph API (neither via FQL).
Facebook prevents this list to be accessed to discourage selling fans data to 3rd party companies (and as a subtle way to prevent competition of targeted ads).
However, with the Like button plugin endpoint URL (https://www.facebook.com/plugins/fan.php?connections=100&id=XXXXXX) you can parse the HTML and saving the new ones appearing there, iterating a call to the endpoint every X seconds. Just be careful as this is really not allowed on Facebook TOS and you can be banned (or even get a legal complaint) by implementing that.
Cheers!
I would like to know if anyone else has experienced this problem...
Facebook's count of mutual friends is off by 1. One too much. But not for all friends. I've tested this through my app where the fetched mutual_friend_count does not correspond to the number of mutual friends in the fetched array.
Further I have been checking this manually. By going to a FB-profile and literally counted our mutual friends. This also shows that we have one less mutual friend than the number Facebook is displaying in the "Mutual Friends" section on a friend's profile.
This does not apply for all my contacts on Facebook. Some profiles are displaying the number of mutual friends corresponding to the actual number of mutual friends.
But this do posses a problem if you are building an application/wesite/facebook app etc. that somewhat relies on the mutual_friend_count.
Can anyone confirm this? Is this a bug?
Or is it some kind of setting that some users can avoid being shown in the mutual friend section, but is still counted...?
I've been doing some work with mutual_friendsand I figured I'd give my 2-cents on what I've learned on this issue, which may or may not correspond to whats not working on yours.
Documentation for mutual_friends via Facebook Graph API is here
From the docs:
The user in the request and the session user must both have granted user_friends permission to the app.
This is a common mistake I was making. Even if you have mutual friends between users, if the friend has not given permission to the app, then you can't get their picture/name or any info on them, they simply appear in the total_count parameter.
If you want to call this endpoint on behalf two app-users who are not friends, then you must provide the appsecret_proof parameter along with the user access token when making the request. This means you must call this endpoint from your server.
This is also very important. If the two users aren't friends, then this endpoint will silently fail you providing NOTHING even though they have mutual friends. In order to actually get the data for this scenario, you need to be calling the endpoint from your server, not your client. That means not your javascript webapp, not your android app and not your iOS app.
There are some additional edge cases, such as users not providing the mutual_friends permission to your app, among other issues but at least for me these were the main issues I ran into. I never had any off-by-one errors, so I can't confirm your bug.
I can confirm that the mutual friend count is reduced by 1 sometimes. I counted a few, and some are right, and others are 1 less then it should be. It could be a setting in the privacy tab, I'm sorry I'm not much help.
I've noticed that using the new Facebook Graph API to fetch friends of users returns a number of friends that is close to, but not always exactly, the number of friends displayed on the user's profile.
Documentation here: http://developers.facebook.com/docs/api
For example, on that page, I click on https://graph.facebook.com/me/friends, and see the JSON for 477 friends, whereas my profile page on facebook shows a count of 478.
Does anyone know why there is an inconsistency?
If you have friends that have opted out of the Facebook Platform, they will not show up in the API response.
After being frustrated by inconsistent friend count, I asked a former Facebook engineer about it. It's a known bug related to their usage of memcached, and is considered too expensive, difficult, or otherwise not worthwhile to fix for now.
My two penneth: I've noticed that the number of friends which is displayed in my profile fluctuates (by 1)! I don't know what the reason for this inconsistency is but I suggest you keep checking that number in your profile regularly and see whether it's the case for you as well.
In terms of the Graph API the discrepancy between the friend count in my profile and in the data returned by the API is 2.