Facebook getUser returns wrong ID - php

I have an problem in my app. The only thing I need from a user is there facebook id. After they log onto facebook they are redirected back to my app and I can get the userID with $facebook->getUser(). This works fine except when the user has chosen a username on facebook. Then I get a really weird long ID that is different from the userid.
To clarify, let's say I ask the userid from a user that hasn't set a username, I get for example the id: 1234567891.
When a user has set a username, I get an ID like: 100002339295322.
Anyone maby knows how I can solve this ?
If you need code samples of how I do things, I do them as told on the facebook developers site: http://developers.facebook.com .
With friendly greetings,
Bob
PS: I use the CodeIgniter framework and the official facebook php sdk
*/// EDIT \*
The problem is solved. Apparently it had something to do with the datatype I used for the field. I changed it from int to varchar and now everything is working.

I had a similar problem, and found out that after v2.0 API user_id is app scoped. I had two user_id for the same user's profile but different application, and both are valid for their respective app.
You can reach the user profile with
http://facebook.com/app_scoped_user_id/<USER_ID>
You may also query the graph api, using the app token and the app scoped user id.
Ref.: https://developers.facebook.com/docs/apps/upgrading/#upgrading_v2_0_user_ids

Not all facebook users have usernames but they ALL have user ids. (e.g. it's optional to have an alphanumeric username, just gives easy access - facebook.com/johnsmith or smth)
Your best bet is to store the ID (the 10 or so digit number) and if you're storing names, perhaps store their first name like stackoverflow does.

For those coming here after 1 May 2014, Test Apps now default to the v2 API, which will cause problems if your app was built using v1. See last post in the FAQ here https://developers.facebook.com/docs/apps/test-apps

Related

Facebook API return different IDs for the same user [duplicate]

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user
{
self.profilePictureView.profileID = user.objectID;
self.nameLabel.text = user.name;
NSLog(#"My ID:%#", user.objectID);
}
I have tried to print the user id using the above code. And what I get is 3176144783XXXXX.
However, I got a different one using this online tool http://findmyfacebookid.com/. The result is 1000042591XXXXX.
Does anyone know the difference? Why do my app and 'findmyfacebookid.com' receive a different user ID for the same user?
Note: My mobile app need to use the FB unique ID to create my own user database. So this is the reason I need a unique ID.
Since v2.0 of the Facebook API the user IDs returned to your app are scoped to your app (i.e each app receives a different identifier for any given user) - you can't compare what that site is telling you to what your app received when you called user.objectID because they're intentionally different strings
Use the ID returned to your app as the identifier for users in your app - there's no need to try and find the 'real' or 'old' user ID - there's no reason for you to need to use the user ID given to any other app ID
There's more information about that the changes from v1.0 to v2.0 here: https://developers.facebook.com/docs/apps/upgrading
And the app-scoped IDs are specifically discussed here, including a way for developers with multiple apps to corelate the IDs for users who use more than one of their apps : https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids

How to Convert Facebook fake user id to real user id [duplicate]

This question already has an answer here:
Facebook API: How to get the FB login user's unique ID? ID from API doesn't match 'real' user ID in v2.0
(1 answer)
Closed 8 years ago.
I am building a Facebook app that will return users who like a product that a business would offer. I am using the Facebook Query Builder located here https://github.com/SammyK/FacebookQueryBuilder to do all of this.
The app is using the Facebook Graph Search API to return pages that match a certain search criteria. Then it looks at who has liked the recent statuses of that page, making them a "warm" lead. I get back a fake ID of a user. Test it out for yourself.
If you go to Facebook / 684351765016845 you will be redirected to facebook / arturo.valencia.37
But the real facebook user id is : 100003260838219 not 684351765016845.
I need to get either the real facebook user id or the user name which is what Facebook redirects to. I've even tried logging in with a curl request and trying to let it redirect me like that is shown here
php get url of redirect from source url
I'm not exactly sure what I need to do. Any help is appreciated.
You can see my test app and the results I get back located here :
http://104.131.178.30/ryan/
Any and all help is appreciated.
Since April 2014 (v2.0 of the Graph API), it´s not possible to get the "real" ID anymore, you only get an "App Scoped ID". It´s not a fake one, it´s unique in that specific App so you can still use it to identify returning users.
It´s not possible to get the "username" either anymore, as it would allow someone to get the real ID.
Check out the changelog for more information: https://developers.facebook.com/docs/apps/changelog

get facebook user-id/username to fetch profile picture without Facebook SDK? PHP

I'm looking for a way to get a users facebook profile id or username which i can use to get the profile picture based on the users account. I know how to fetch the picture already (http://graph.facebook.com/username_or_id/picture). I don't want to ask the user to submit their fb username (or worse - their profile id), i need it all done automatically (happy user).
Now i have not setup a Facebook app to use the facebook SDK so i don't have a appID or a secret code...
The reason for not setting it up is because im working on something that not only i will use. It's a project where others will be able to use on their own domain and i don't want to ask the users to setup their own FB app just to get this working so im looking for a way to do it, without the FB SDK? or have i got it all wrong?
You can do everything without FB SDK (it's just a library), but you can do nothing without application. So no, you can't get user's ID without their knowledge

Getting the user_id through Foursquare Api V2

I'm working on a foursquare integration for a social good website, and I have everything working as I want it to, however I want to retrieve and store users foursquare user_id's so others can search for their friend. I've been searching all day, but I can't seem to find an end point, am I missing something? Or does this has to be done through user search? What is then best to use, as I have their email, and full name.
I am using jmathai's foursquare-async php libary. I think it should be easy but I just can't figure it out.
I've found the solution. To get an users' details you should use the end point "users/self". I had tried this before but got an error message. I think that was related to something else now.
After authenticating two lines are simply enough:
<?php
$fsObj->get("/users/self");
print_r($creds->response);
?php>
This gives an json array containing all relevant information on the user, including last checkins, name, and id. 'self' can here also be replaced by any user id you're authorized for on that moment.
For more information I'd recommend to visit Foursquare Api website

Getting a friend count from Facebook (possibly using api)

I'm used to working with Twitter, where friend/follower totals are available in a simple XML request.
My goal is a simple "enter your username/user id, and display your friends count".
Is there something like this for Facebook? From what I gather, I'll have to make an application, and have anyone who wants to grab their friends total actually install that app from within their own Facebook profile.
Anyone have any experience with this?
You can get friend count by fql easily.
There is a friend_count field against the user table that you can query.
SELECT friend_count FROM user WHERE uid = me();
https://graph.facebook.com/fql?q=SELECT friend_count FROM user WHERE uid={any id}
You do need to set up an application, but it'll work as a Connect app - meaning that users won't have to access it through their Facebook profile at all. In broad terms you'll need to:
Set up an application
Implement Facebook Connect on
your site
Get users of your site to log in
with Connect. (You can't ask for
their username/password.)
Make a Friends.get call to the
API, probably with the JavaScript
client library (although there
are server-side ways you can do it)
Facebook provides an API for developers so you can grab information from Facebook. Check it out at the provided link.
Edit: From your tags, it looks like you are already familiar with the Facebook API. You can use the API with external applications or webpages - it doesn't necessarily need to be used within a Facebook app, if that is what you are asking.

Categories