Getting number of people who like a page on facebook by city - facebook

A question than has been floating around is how to get the list of IDs of people that like a page (here, or here, for instance). From previous answers (and reading the FB API docs...) I am convinced that to be impossible.
However, that is not what I'm after. I don't need the user_ids at all. I just need the number of likes of a page, per city (or some subdivision of a country). There is a field for a Page for the total number of likes, which obviously isn't enough. Insights should provide this, but while page_fans_country works ok as the info is public, page_fans_city returns no results, so I'd need a different way of getting the information.
Is there a query (or set of queries) that would work? Either Graph API or FQL would be fine, at this point.

As to your first statement, I have found that to be correct aswell. My current solution includes, as it has to, external storage.
On to your actual question, it is possible via the Insights API you've found yourself. Rather than moving on from page_fans_city (because it returns no results), you should find the issue. Most likely, you're using a User Access Token without the scope manage_pages, which prevents it from becoming a Page Access token. You should also include read_insights. Read more here. For further information about the object/insights go here.
Hope this helped.

Related

How can I search for taggable_friends (FB API) form within my app without using a limit on my request?

I am currently using Facebook's OpenGraph to obtain taggable_friends. By default and as of FB API > 2.1 the request only returns 25 objects. You can add a limit and increase your data response but you have no parameters you can pass. It just doesn't feel right to increase the limit with a hard coded number. So, one of the features of that app is that you can search for taggable_friends and select them. If you return a large limit to obtain (in most cases) all of your friends can take a while. Let's say you only get the first 25 and you search for a person that is in a batch - you don't know where. Since you have no parameters to pass to your request, a searchTerm for your your API call is out of the question.
Has anyone ever done a batch call? Facebook allows for multiple requests using some sort of batch calls. How would that look like in JS code?
I can use my users information to obtain the amount of friends he/she has and set a reasonable limit. That helps in the majority of cases but doesn't solve the problem.
Did someone ever encounter that problem and solved it?

Can only access sharedposts for some Graph API objects?

I have an access token for a page on Facebook. I can view that page’s feed, and individual posts in that feed. But for some reason, I can only request the /sharedposts endpoint for some of them using v2.2 of the Graph API.
The access token has the user_posts and read_stream insights. When I request the shares field I can see more than one post with shares, but when I request [POST_ID]/sharedposts for some of them, I just get an empty data array in response.
Why is this? Are there some gotchas I should be aware of? It’s a tad frustrating that the /sharedposts edge will return returns for some posts but not others using the same access token and API version.
This is a know bug, which still seems to be unsolved.
Basically it should work like you expected, but even with all necessary permission (and even for public posts) it does not return the object with each of the shares.
You probably want to subscribe to the bug here to be noticed once it has been solved:
https://developers.facebook.com/bugs/1404733043148335/
I just posted my insight/workaround for this bug on the bug report that lars.schwarz linked to, but I'll paste it here as well:
/sharedposts will only retrieve public posts or posts from users who have granted your app access. HOWEVER, the endpoint does not seem to query for this intelligently. I'm not sure, but I think the endpoint has a default limit of 25 results. What appears to be happening is that the endpoint queries Facebook's database for 25 posts, then filters that set based on your app's permissions.
What this means is that if the most recent sharedpost your app is allowed to access is 30 posts deep, the endpoint will return an empty data set. If your app is allowed to access one post which is 15 deep, and one that is 30 deep, it will only return the post that is 15 deep.
In order to get around this, you can set a really high limit (I've been using 2000). The problem with this is that if your post has more than 2000 shares, you will still miss stuff. You can't make the limit insanely high, unfortunately, because the endpoint will return an error telling you to query for less data (even if the query would only actually return a handful of posts). Therefore, I've been setting a limit of 2000 and using the "until" parameter to move through the sharedposts chronologically.
Hopefully that helps clear things up. This is a major pain, and an imperfect solution (although it gets 99% of the job done I think). I encourage everyone to file a bug report on this here: https://developers.facebook.com/bugs
It appears that this bug has been around for years, and I was told yesterday that they have no short-term plans to fix it. If we file enough complaints, maybe they'll prioritize it higher.

Read all ad campaign from Facebook Marketing API

I'm using Facebook Marketing API to get ad campaingn from Facebook. I'm getting the data, but the problem is, they are sending the data with pagination. I have the url for the next set of data, so I need to call the Facebook API multiple times. I can set the data limit in the request to a huge number so that I can get all the data at a time.
Is there any other option to get all the data?
I tried with until & since parameter and sending the timestamp of current time & 0, but it didn't worked.
So is there any other way out?
Paging through the data is the way to go. There is no alternative.
There are indeed different ways to use paging, one of which would be to use the next/previous links provided in a response. Another way is to use so-called Cursor-Based Pagination, where you construct your own next/previous links using a provided cursor tokens. This is documented here.
Please not that you can indeed change the requested limit to some huge number, but Facebook's API may silently reduce that number to whatever it thinks is sensible, or it may return an error saying that you requested too much data. Summarized, this means you will need to use paging.

Returning compact user (not mini) with foursquare checkins

I want to get all of a user's friend's checkins, and be able to find out that friend's facebook id without having to make an additional request. This is only included in compact and complete user objects, not in mini user objects which are returned with checkins.
Looking through the API docs, it appears that there is no way to request specific fields, or modifications to the results. This seems silly and a bit unlikely since that wastes a ton of resources on both sides of the API, so I'm curious if there is a way to do this that hasn't been initially obvious to me.
Unfortunately cherry-picking fields you want back in a response isn't supported by the API; you'll have to make the additional request.

Facebook social network analysis on my page's comments/shares/likes

Let me explain the whole thing here so you can have a clear picture of the situation:
I have a page on facebook and the insights (both on the page and from the graph api) give me a lot of valuable information, but I need to go deeper. I was thinking of applying the social network analysis concepts (centrality, betweenness, eigenvector, etc) on who likes/shares/comments on my pages posts/pics/etc, so I can find the key-users of my page and how virality spreads among them.
Lets take 'liking a post' as an example. First thing I need is to get a list of everyone who liked that post, which is simple and can be done with a few requests to the graphapi. Now comes the tricky part: I need to know the relationship between all these people who liked the post, but I don't have access to their friendlist. To have access to the friend list I'd have to make the page an app and request that permission, which can't be done at this point. But facebook api allows you to check if two individuals (user1 and user2) are friends with a request like this: user1/friends/user2, and for that I don't need special permissions, just a regular token. Well, so far so good, I just get the users who liked the post and check two-by-two which ones are friends. But here comes the problem:
I can make batch requests to the API, which means I can check 50 pairs of users with one request. And from what I read, facebook allows 600 requests each 600 seconds. Simple math: 30,000 pairs of users each 10 minutes. It's a big number, should be enough. It isn't. Let's assume that the post has 1,000 likes (not being optimistic at all). I'd have to check user1 against the other 999 users. Now user2 would have to be checked against the remaining 998 users (no need to check against user1 again, because the friend-check works both ways). User3 against 997 users and so on, until user999 needs to be checked against 1 user. Therefore I'd need to perform 999+998+997+996+...+3+2+1 checks, or 499,500 requests, which means almost 3 hours to get the data obeying facebook limitations. 10k likes would take over a week!
So my question is: is there any other way to make this work? Another way of getting data, or a largest batch request? Some way I can retrieve this data? Or it's just impossible, since facebook retains the important information?
Thank you for reading all this and helping me out ;)
What you are trying to get to is information that Facebook does not want easily available.
In the same way that you don't have access to "friends of friends", trying to reconstruct social connections takes far too many calls to the API since, as you stated, you would need to test against individual pairs.
Whilst your question is valid and from what I can tell you are not trying to obtain this data to to perform some malicious actions, I'm afraid that at this point you'll just have to use the data that Facebook makes available to you through the Insights application and the access to that data though the API as well.