Getting the profile ID of a Facebook user? [duplicate] - facebook

This question already has answers here:
Get Facebook User ID with Facebook App Scope ID
(3 answers)
Closed 2 years ago.
This is different from the app ID, which is an ID associated with the app itself. How can I get the user's actual ID (or the profile ID)?

You could use the /me:
The /me node is a special endpoint that translates to the user_id
of the person (or the page_id of the Facebook Page) whose access token
is currently being used to make the API calls.
curl -i -X GET \
"https://graph.facebook.com/v9.0/me?access_token=<token>"
Will return
{
"name": "<name>",
"id": "<id>"
}

Related

I can't get events from a facebook page even with administrator rights [duplicate]

This question already has answers here:
Facebook Graph API does not return Page Events
(2 answers)
Closed 4 years ago.
I had a working calendar that gets all events from a facebook page. Since about a week it stopped working. If I now test what is in the events object of that page, it is completely empty, but when I go to the actual page on Facebook, it's filled with events..?
Did Facebook change their api or policies all of a sudden? I can't find anything on that.
Why is this:
https://graph.facebook.com/v2.10/705097199526713/events?fields=owner,start_time,cover,description,name,place&limit=100&access_token=myaccesstoken
Giving me an empty result?
{
"data": [
]
}
But look here. Lots of events.
I even got a non expiring access token with full permissions, like manage_pages following this post.
Access Token Info
App 2352352332: metz-nederland
User 2345325235: me
Page 705097199526713 : youCANbe
Valid True
Scopes read_insights, manage_pages, pages_show_list, public_profile
I hope somebody knows why this is happening.
Unfortunately, the Pages events API edges were deprecated in recent changes.
Events API
Deprecated:
Endpoints that return data including /feed, /posts, /comments, and the RSVP list.
See here for more information:
https://developers.facebook.com/blog/post/2018/04/04/facebook-api-platform-product-changes/

Facebook friends request returns empty -- despite permissions [duplicate]

This question already has answers here:
Facebook Graph API v2.0+ - /me/friends returns empty, or only friends who also use my application
(8 answers)
Closed 6 years ago.
I'm building a Rails backend for an iOS app. The backend needs to interface with Facebook to grab and use each user's Facebook friends.
But the Facebook 'friends' request is returning empty.
I'm essentially making the following request:
curl https://graph.facebook.com/[FILTERED_USER_ID_FOR_APP]?fields=friends&access_token=[FILTERED]&debug=all
I've looked at a ton of StackOverflow posts about this (this one, and this one, and this one, and more), but haven't found an identical problem or a solution that fits.
I seem to have set permissions correctly. Both on the Rails app and when the user authenticates through the iPhone app, I've set user_friends to be one of the permissions, and, in fact, when someone registers now, it asks them to OK the user friends permission.
But when I actually request their friends, I get a response telling me that there are many friends, but not returning any of them. The below response is for a user who definitely has friends on the app.
{
"data":[],
"summary": {
"total_count": 419
},
"__debug__": {
"messages": [
{
"link": "https:\/\/developers.facebook.com\/docs\/apps\/versions\/",
"message": "No API version was specified. This request defaulted to version v2.7.","type":"warning"
},
{
"link": "https:\/\/developers.facebook.com\/docs\/apps\/changelog#v2_0",
"message": "Only friends who installed this app are returned in API v2.0 and higher. total_count in summary represents the total number of friends, including those who haven't installed the app.",
"type": "info"
}
]
}
}
What's perplexing to me is that a) The App ID/User ID/Access Tokens seem right, because I can get basic profile info, and b) I do not get an error telling me that the request doesn't have the proper permissions. If I make a similar request without permissions on the explorer, it returns a relevant debug note:
{
"message": "The field 'friends' is only accessible on the User object after the user grants the 'user_friends' permission.",
"type": "warning"
}
If I make it with the right permissions in the explorer, it returns a list of friends (in the data array).
So it doesn't seem to be a permissions issue, but the request is returning an empty friends list. Any ideas?
With Igy's help (pointed to this answer), I found the specific answer to my issue, which seems worth adding here.
The problem was that the new 2.0+ API version only returns friends:
Who are on the app
Who have agreed to the user_friends permissions themselves.
1 was all figured out, but because I'm still testing the app out, and nobody had yet accepted permissions, my test user was the only person who had accepted permissions. Nobody else had accepted user_friends, so nobody showed up as a friend of the test user. Getting a friend of the test user to add the permissions fixed the problem, adding that friend to the list of friends returned.

How to find the Facebook ID? [duplicate]

This question already has an answer here:
Facebook - "Cannot query users by their username" solution
(1 answer)
Closed 7 years ago.
When i go to http://graph.facebook.com/harshamv i get the following error
{
"error": {
"message": "(#803) Cannot query users by their username (harshamv)",
"type": "OAuthException",
"code": 803
}
}
Is there any way i get get my Facebook ID?
You donĀ“t need global IDs anymore, only App Scoped IDs. You get them by authorizing a user with no additional permissions and a call to the /me endpoint.
More about the change can be found in the changelog:
https://developers.facebook.com/docs/apps/changelog#v2_0
More information about the same error message:
Facebook - "Cannot query users by their username" solution
Social framework returns "(#803) Cannot query users by their username (username)" when trying to get user feed
Facebook Graph API v2.1: getting user id and his posts

How can I get a list of all locations and hometowns used by Facebook? [duplicate]

This question already has answers here:
List of countries and cities to be used in Facebook Graph API for targeting
(6 answers)
Closed 9 years ago.
When I access the Facebook Graph API and find a location, I get something like this:
"location": {
"id": 108131085886116,
"name": "Saint Petersburg, Russia"
},
Each location has its own ID. Is there a way I can get a list of all locations that Facebook knows about? Where can I download it?
No, you can't get a complete list - but depending on your use-case you could just slowly build one out as you encounter new values in your app users' profiles.
You can also search for places by name and location as a core part of the API

how to check if user like a specific Facebook page or not [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to check if a user likes my Facebook Page or URL using Facebook's API
how to check if user like a specific Facebook page or not from my website (using PHP or Javascript)
Fb App ID = 123456
Fb App Secret = `0123456789
Fbpage = http://www.facebook.com/mypage
my website = http://www.example.com
ex:
if user like Fbpage then
say "u are a fan"
else
say "u are not a fan"
From the Graph API likes documentation:
Belongs
You can check if a User likes a specific page by issuing an HTTP GET to /PROFILE_ID/likes/PAGE_ID. This will return, in the data array, an object with the following fields if the user is connected to the page.
You'll need a valid access token with the user_likes permission.
In Javascript, this might look like:
var page_id = 123456; // whatever
FB.init({
// ...
});
FB.login(function(response)
{
if (response.authResponse)
{
FB.api('/me/likes/' + page_id, function(api_response)
{
// if empty, they don't like. if not empty, they do
console.debug(api_response);
});
}
}, {'scope': 'user_likes'});
You need to use the likes end point (http://graph.facebook.com) this is a json representation of a user's likes , interests etc. Just parse the list for your page id.