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

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

Related

Facebook API Integration

I am trying to integrate FB with my website. (USING PHP)
1.) In that I am in need to list all the groups related to my loggedin in user in my website who is connected with their FB account in it(I have oauth_token too). Also i want to allow my user to post something in their FB group listed here using FB API.
2.) Next thing I want get all the frd list of the logged in user and to post messages/wall post to them.
I tried more in google I am not able to know whether it is possible or not. I have done only FB login integration and posting in wall.
Can any one please tell me whether the above 2 things are possible or not. Thats enough. If possible I can contiue surfing on that and make it. If not possible I'll stop surfing on that.

Getting users news feed from Facebook

In my portal, I have added user login and getting user profile information from facebook.
My next target is to get the news feeds which appear on the home page of user. I refered to this question but the accepted answer said it is not possible. Is it really not possible or there is a way to do it in present fb api?
The accepted answer at How to get user's news feed via graph api was over a year ago, whereas the other answer is 5 months ago. As documented at https://developers.facebook.com/docs/reference/api/user/#home , the usage https://graph.facebook.com/me/home works, which I tested in the API Graph Explorer Tool and it worked. Let me know if it works for you :)

Facebook getUser returns wrong ID

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

Pulling Public Facebook Posts Into PHP Page

Last December, I set up an app for a client who wanted to pull their public facebook posts into the footer of their website.
I was using this URL to pull the message, create time and permalink and when I wrote it, all was good:
http://api.facebook.com/method/fql.query?query=SELECT%20message,%20created_time,%20permalink%20FROM%20stream%20WHERE%20source_id=138631878804%20AND%20message%3C%3E%27%27%20limit%203
Today they reported that it was no longer pulling their information. I put that url into a browser and the result is "Requires valid signature"
I've gathered from google that I need something called an access_token, also I've seen where I can use the php sdk but then I need an appId and a secret token.
At this point, I've read so many different sources that I am thoroughly confused. The FQL query above represents the full extent of my Facebook programming experience. It looks like maybe I want the Graph API, but I don't want anyone to have to sign into anything.
Can one of you guys who are more versed in the voodoo of facebook nudge me in the right direction to do this:
From PHP, pull public messages from the stream table without forcing a user to log into facebook.
Thanks!!
To pull posts from a publicly visible Page on Facebook, you can use any valid access token. For most sites managing a page, this will be a page access token retrieved via one of the page's admins authorising your app to have access to their pages, but that might be overkill for your use-case.
Probably the quickest solution is to just create a new App ID for the site, get the app access token for that App (see 'App Login' on https://developers.facebook.com/docs/authentication/ ) and then use that access token to retrieve the posts.
I found several links all from a simple Google search.
Duplicate question: https://stackoverflow.com/questions/3298836/how-you-get-access-tokens-for-facebook
http://benbiddington.wordpress.com/2010/04/23/facebook-graph-api-getting-access-tokens/
https://developers.facebook.com/docs/authentication/

Simple Facebook status return using FQL

I'm trying to create a box on the side of a page that displays the 6 latest posts from a Twitter account and Facebook page. Twitter is working exactly how I want it to - Facebook is not.
The way I am doing it at the moment is to fetch the latest statuses using FQL as JSON usin cURL, caching them on the server, then displaying them in the same way as I am the tweets in the actual box.
My problem lies with the access token. I went away last night with it working, came back this morning and noticed that the modified date of my cached file hadn't changed. I checked the cached error file (where the fetched JSON gets dumped if it doesn't contain the data I need) and I had a session expired error. I then created a small function that uses cURL (3 cURL calls or one box, I know - urgh) to retrieve a new access token using the this URL:
https://graph.facebook.com/oauth/access_token?grant_type=client_credentials&client_id=XXX&client_secret=XXXX
But I now get an error that a User Session is required, but all I want to do is to read the latest posts, that isn't user dependant at all. I really want to avoid using the Facebook SDK if possible.
Tl;dr - FQL seems to require users to log in even just to read statuses off of a set page's wall - what's the correct way of getting this data that doesn't require a user session (preferably without using the SDK).
If you're trying to get the status from a User account then you will require a valid user access token.
If you're getting statuses from a Fan Page then you just require a valid app access token - which can be obtained from:
https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials
You can then use the returned access token to get the statuses from the target Fan Page.
SELECT id,status_id,message,time FROM status WHERE uid = XXXX LIMIT 6
You're querying by user id so that will require a valid user access token.

Categories