I'm looking for a way to list all pages where a given user is an administrator. Is this possible? If so, where should I be looking?
Not sure what you are looking to accomplish. If you want to prompt the user to add your app to a page the are an admin of, you can do it through the javascript SDK. (https://developers.facebook.com/docs/reference/dialogs/add_to_page/)
Otherwise, you need to use FQL to query for the information. (https://developers.facebook.com/docs/reference/fql/page_admin/)
You'll need the manage_pages permission from your user in order to gain access to this information.
Using Facebooks FQL and the Graph API you can make a query to the page_admin table using the uid index to reference your user.
https://graph.facebook.com/me/fql?q=SELECT page_id, type from page_admin WHERE uid=me()
An alternative :
The /me/accounts Graph API endpoint
In the Graph API's documentation under the user endpoint there is details about the accounts connection :
The Facebook apps and pages owned by the current user.
You also need the manage_pages permission from your user here.
Here is a sample output from a call to that endpoint :
https://graph.facebook.com/me/accounts?access_token=ABC
...
{
"name": "Unicorn Ville",
"access_token": "XXX",
"category": "Application",
"id": "123"
},
{
"name": "StackOverflow'em Poker",
"access_token": "YYY",
"category": "Application",
"id": "456"
},
{
"name": "The Official Bausley Page",
"access_token": "zzz",
"category": "Non-profit organization",
"id": "789"
},
...
Note that /me/accounts returns "apps and pages owned by the current user"; As such the results you will get will have to be filtered, removing all the application entries or alternatively extracting only the non "application" values of the category parameter.
Related
I am trying to get mutual friends from facebook but it is giving me wrong result. The total number of mutual friends count which I am getting is right but when the data is users is not coming
Request
https://graph.facebook.com/v2.8/1744744292507346?fields=context.fields(mutual_friends{name,picture.type(large)})&access_token=access_token
Response
{
"context": {
"mutual_friends": {
"data": [
{
"name": "Gaurav Varshney",
"picture": {
"data": {
"is_silhouette": false,
"url": "https://scontent.xx.fbcdn.net/v/t1.0-1/p200x200/15541198_1872071033026134_3669335060573505093_n.jpg?oh=d4a95ee6cdb8d401be06e8f10fbf6d50&oe=59B0C911"
}
},
"id": "1919297771636793"
}
],
"paging": {
"cursors": {
"before": "MTkxOTI5Nzc3MTYzNjc5MwZDZD",
"after": "MTkxOTI5Nzc3MTYzNjc5MwZDZD"
}
},
"summary": {
"total_count": 2
}
},
"id": "dXNlcl9jb250ZAXh0OgGQHYKW1ALzRNZBAkUhMk2uDFtLZBBkzlasCZAq98zEqnPZBjqy7beHZBJZCVZB7STTw6yMnKC0w4qDA05ZBOGQ3RdRoPjfi1cbAmnChBQ1xLYpJuuKrIEZD"
},
"id": "1744744292507346"
}
I am only getting 1 friend since total_count is showing 2 .Can anyone tell me where I am doing wrong?And how can I use paging ??
When try to hit all_mutual_friends
https://graph.facebook.com/v2.8/1744744292507346?fields=context.fields(all_mutual_friends{name,picture.type(large)})&access_token=access_token
{
"error": {
"message": "(#10) To use all_mutual_friends on behalf of people who are not admins, developers and testers of your app, your use of this endpoint must be reviewed and approved by Facebook. To submit this feature for review please read our documentation on reviewable features: https://developers.facebook.com/docs/apps/review",
"type": "OAuthException",
"code": 10,
"fbtrace_id": "HF3ZO8U3eLW"
}
}
There is a lack of documentation about this feature and I had to dig about it. Mainly regarding on how to request that with Graph API.
That's how I'm doing and it is working, with some flaws that I will explain later:
Let's say we have here UserA and UserB. You need to collect the context-id of each of the user and save it on the server side because it must be used later on.
So, UserA connects and want to request mutual friends with UserB which is already connected. What you will need to do is:
UserA FB Graph request using this:
/'{{UserB context-id}}/all_mutual_friends?limit=5000', 'get'
also sending UserA fbaccesstoken
I use the limit 5000 to avoid pagination on the data results.
Now, the flaws:
The all_mutual_friends is giving me some headaches. I may be completely wrong, of course, but I debugged it for days and it seems there are some issues with Facebook when the feature is still in development mode and not public/authorized by FB. Don't know, I need to ask for permission to see that in production.
On my application I realised there are sometimes some mutual_friends are not actually listed and it is not a fault of the script, but probably some users configuration that avoid using this or some facebook problem. IDN.
Anyways, that's the way you should request mutual friends.
Hope it helps.
I'm grabbing Facebook Post's pictures via Graph API call:
GET /mypageid/posts?fields=id,created_time,picture
Here's a sample response:
{
"data": [
{
"id": "1389378987988776_1745791089014229",
"created_time": "2016-08-03T21:55:39+0000",
"picture": "https://external.xx.fbcdn.net/safe_image.php?d=AQBQL02u4kJtLNFs&w=130&h=130&url=fbstaging%3A%2F%2Fgraph.facebook.com%2Fstaging_resources%2FMDExNzQ1NzkwNjg5MDE0MjY5Ojk5ODEyOTY4Ng%3D%3D&cfs=1"
},
{
"id": "1389378987988776_1745301615729843",
"created_time": "2016-08-02T18:10:53+0000",
"picture": "https://external.xx.fbcdn.net/safe_image.php?d=AQD7O17OAki29Gus&w=130&h=130&url=http%3A%2F%2Fcdn2.obsnocookie.com%2Fwp-content%2Fuploads%2F2015%2F03%2F13995025_770x433_acf_cropped.jpg&cfs=1"
}
}
Does the picture URL have an expiration date?
There is no specific expiration date afaik, but you should never rely on CDN links being available later according to Facebook. If you need them, you can download and store them on your own server.
I'm currently writing a PHP application.
I noticed something strange when it wasn't returning the persons birthday.
To cut a long story short, when i manually query the graph api, it gives me the full result set (birthday, email etc. included). However, when I run it in my app, it comes back as if i've not sent the access token.
When I manually visit the address it produces:
{
"id": "507665705",
"name": "Ally Dewar",
"first_name": "Ally",
"last_name": "Dewar",
"link": "https://www.facebook.com/alastair.dewar",
"username": "alastair.dewar",
"birthday": "06/22/1990",
"location": {
"id": "113744028635772",
"name": "Greenock"
},
"gender": "male",
"email": "alastair\u0040alastairdewar.co.uk",
"timezone": 1,
"locale": "en_GB",
"verified": true,
"updated_time": "2012-03-11T15:56:19+0000"
}
However, when my application makes the same request (exact same URL), it comes back with
{"id":"507665705","name":"Ally Dewar","first_name":"Ally","last_name":"Dewar","link":"http:\/\/www.facebook.com\/alastair.dewar","username":"alastair.dewar","gender":"male","email":"alastair\u0040alastairdewar.co.uk","locale":"en_GB"}
My instinct says it could be a setting within the facebook app, as it wasn't a problem beforehand.
EDIT: https://developers.facebook.com/bugs/412680422092698?browse=search_4f854dc037a2a5d12811839
Thanks for any advice.
Make sure you ask for all the permissions that you need and also remove the app and start again. Make sure you ddon't cache any of the responses as well.
How do you query the API? Graph Explorer or just manually open the link (graph.facebook.com/USER_ID) and pass the auth token generated by the app? Testing with the Graph Explorer won't help you with your problem as permissions etc are different.
As mentioned by Nobita, code helps. This is as much as I can advise considering the amount of data you're giving us.
Having the following url I get all the pages I admin and applications I created. My goal is to show all the pages I admin and not the applications in an external PHP file.
https://graph.facebook.com/me/accounts?access_token=xxx
Is there another url for this specific task or I have to find a way of filtering the follow? The fields are the same.
{
"data": [
{
"name": "",
"access_token": "",
"category": "Professional sports team",
"id": "159960057362822"
},
{
"name": "",
"access_token": "",
"category": "Application",
"id": "155960053362822"
}
]
}
The same goes using FQL like SELECT page_id, type from page_admin WHERE uid=me()
it shows the applications also.
I have not created pages for applications.
With the Graph API you'll need to iterate over results to manually filter everything with category Application (currently where is no filtering for this in Graph API)
With FQL you can do this by issuing next query:
SELECT page_id, type FROM page_admin WHERE uid = me()
AND type != 'APPLICATION'
AND type != 'APP'
I have been playing with Facebook Graph API around a week, and I still could not find how to get user's network information? I don't know if the Graph API stores user's network; I didn't see such information. Simply, if a user is in "Google" network, may I get the name and the ID of the networks that the user belongs to?
If this is not possible, may I reach the user's secondary email addresses?
Thanks for your help.
Using FQL : the affiliations field of the User table contains this information
Sample call:
https://graph.facebook.com/fql?q=select affiliations from user where uid= 4&access_token=<ACCESS TOKEN>
Sample response:
{
"data": [
{
"affiliations": [
{
"nid": 16777217,
"name": "Harvard",
"type": "college"
},
{
"nid": 50431648,
"name": "Facebook",
"type": "work"
}
]
}
]
}