How to get FB id without connecting - javascript

I know at first this sounds evil, but I'm not trying to be at all. I'm only trying to get the users Facebook ID without having to connect to FB. I basically want to unique the user on my site by their social id.
If you use facebook's comments feature, without being connected, they have your ID and picture. The picture is easy because it's just a URL, but that ID, how do they get it?
Obviously they use iFrames, and maybe that's where the story ends. Because of cross domain scripting I can't get into that iFrame to grab the ID. This is a case where it's so close yet so far away. I can get there via dev tools but I can't get that ID via JS.
So the question is, does anyone know a way to get a users facebook ID without having to connect to facebook first.
Thanks!

Sorry but you cannot do this, as Facebook does not expose this data without explicit user consent.

Related

Facebook API - Pages - Get names of subscribers

I want to get the names of the subscribers of my facebook Page (I want to thank them and develop a single page website who mention each of them).
I use jQuery?
I have not find anything in the doc.
There is no API to get the fans of a Facebook Page. If you mean the followers of your User profile, that is not possible either. You should actually treat them as if they would be anonymous.
Btw, you would not be allowed to put them on an external website without their permission anyway.

Facebook Graph API - Get profile picture prior to authenticating

Ok so i've tried the following:
FB.api("/me", {fields: "picture"}, function(response){
console.log(response);
});
And i'm trying to work around http://graph.facebook.com/USERNAME_OR_USERID/picture since obviously i don't know the users ID prior to authenticating.
All i want is a "modern" feel within the website, so i'd like to present the user with his or her's profile picture on the "login" div presenting the facebook login button. Is this possible? I know that Facebook and their graph api prohibits most such features but i would hope that a public profile picture would be accessible through the graph API..
I've Googled around and all the solutions say "use the USERNAME in the URL and you're fine" but i'm not, so to clear out any doubts, is this possible?
Error message: An active access token must be used to query information about the current user.
You can get everyone's Facebook profile picture without authentication.
You just call http://graph.facebook.com/USERNAME_OR_USERID/picture?type=large. This URL redirects you to image URL.
Type may be normal,small or large.
I also have questions for you:
How do you want to display the picture of someone without knowing who he/she is?
How can you guess which account the visitor will use to connect?
It looks like you want to know whose Facebook account was lastly connected on the browser of your visitor. Technically, you would want to read another site's cookies, which is 1) not allowed 2) impossible.
Several additional things you need to know:
http://graph.facebook.com/USERNAME_OR_USERID/picture is a public way to retrieve someone's photo. You don't need a token for that. What else do you need?
Using FB.API("/me", ...) from the JS SDK implies that "me" represents the connected user. It cannot just be used alone.
By the way, identical questions have already been answered and accepted:
Facebook app without prompted authentication
Get Facebook user's profile picture prior to authenticating app
Why would you hope the impossible?

Creating a facebook likebox

A client of mine (a design studio) asked me to style the like-box social plugin on their site.
As far as I know this cannot be done now with the deprecation of "css" parameter on the fbml tag.
So the route I have to take is to recreate the like-box myself using the js SDK (or php SDK), but the problem is that I cannot find the users (and their photos) that like my page. I'm searching through the opengraph explorers parameters but i cannot find anything.
Does anyone know which url I must follow in the graph api to get what I want?
Do I have to have an access token for such an action? I noticed that the likebox plugin works event if you don't have a facebook account (It shows pictures).
Thank you.
You can't recreate the like box on your own. The Facebook APIs will not return a list of users who like your object. This was done to stop people from getting user lists of likers and spamming them.
Currently, you can only query to find if a specific, authenticated user or which of their friends likes your object.
You could build something similar by populating your fake like box with images of recent posters. You would need to deal with filtering out duplicates, and the page posting as itself, but this should get you started: /PAGE_ID/feed?fields=from.name,from.picture&limit=10
You will need an access_token to get this data. I'd authenticate as an app to do it.

Add something to Facebook stream via URL

I have a userscript (read: my Javascript on someone else's site) that allows users to share their IMDb votes with their Facebook friends. I just generate a URL for a Facebook share page with all of the custom information needed for the specific situation, something like "So and so gave the film Forrest Gump a rating of 9/10 on IMDb" with links to a thumbnail and the movie page itself, and allow the user to add their their thoughts on the movie itself.
script with Facebook share dialog http://s3.amazonaws.com/uso_ss/10985/large.png?1284850755
Until recently, I accomplished this by passing all of my parameters to http://www.facebook.com/connect/prompt_feed.php. Yesterday this broke, and it appears that Facebook is deprecating this sharing method in favor of using their Dialog code. (All of the official FB docs now refer to prompt_feed.php as the "old" way of sharing.)
I found a temporary workaround here that just adds a display=touch variable to the prompt_feed query string. This URL is working for the time being (go ahead and click it!), but I fear that it's a loophole that Facebook will close as soon as they realize it's still available, and I'll be stuck without a way to post stuff to FB.
The current methods of posting to Facebook seem to be 1) using the Dialog URL mentioned above and 2) via Javascript using FB.ui Both of these methods appear to require a Facebook App ID, and when I registered a new FB app for this purpose and tried to use it to create a http://www.facebook.com/dialog/feed request, I got an error because my app doesn't "own" the IMDb page that it's linking to. Any ideas about how to accomplish my purposes going forward?
to "own" the imdb page you just need to set the canvas url to the imdb domain.
you can simply use this url:
http://www.facebook.com/sharer.php?u=http://www.your-url-to-share.com
Just modify or change the http://www.your-url-to-share.com part in the above URL with url of the webpage or article that you want to share on the facebook feeds.
If you use the sharer.php and want text plus a link add the &t={text} to the url. For example:
http://www.facebook.com/sharer.php?u=http://www.your-url-to-share.com&t=text-to-share

How to access Facebook user ID from javascript within a fb:iframe?

I am writing a Facebook application that is a simple board game which I have implemented in javascript. Facebook only seems to let javascript applications run within an iframe so I am loading the page using <fb:iframe>. I just want to be able to tell the javascript the user's id so I can tell the user if it is his turn or not but I can not find documentation on accessing facebook data from within the fb:iframe. I am probably missing some basic conecpt as I do not understand the facebook API very well.
Facebook's API is very tough to follow, and the documentation is very poor. You're right about the Javascript... normal Javascript only works inside an iframe on Facebook, otherwise you're limited to a subset of filtered Javascript called FBJS. You can safely ignore anything about FBJS in the documentation, and focus on iframes.
Iframe loading
The first thing I would mention is that an <fb:iframe> tag actually gets rendered with a ton of stuff in the src attribute. So if you put a tag like this into your Facebook page: <fb:iframe src="http://example.com/page?x=y">, what it ends up becoming when it loads into a user's browser is more like this:
<iframe src="http://example.com/page?x=y&fb_sig_in_iframe=1&fb_sig_locale=en_US&fb_sig_in_new_facebook=1&fb_sig_time=1246340245.3338&fb_sig_added=1&fb_sig_profile_update_time=1242155811&fb_sig_expires=1246345200&fb_sig_user=000000001&fb_sig_session_key=2.d13uVGvWVL4hVAXELgxkZw__.3600.1246345200-000000001&fb_sig_ss=mZtFjaexyuyQdGnUz1zhYTA__&fb_sig_api_key=46899e6f07cef023b7fda4fg2e21bc58&fb_sig_app_id=22209322289&fb_sig=bbc165ebc699b12345678960fd043033">
Facebook adds a ton of stuff to the src. The parameter that tells you the user's Facebook id is fb_sig_user (which is 000000001 here). I'm assuming your app is set up as an "FBML app", since you probably wouldn't use an <fb:iframe> tag in an "Iframe app". Nonetheless, the rendering method is similar in both cases, and you get a bunch of extra stuff to your src document in an "Iframe app" as well.
This really only passes you the Facebook user id on the first load of the iframe, however. Subsequent operations within the iframe won't have access to that user id unless you pass it around explicitly.
Facebook Connect
If you want to interact with Facebook from within the iframe, that's where the Facebook Connect Javascript libraries comes in. The best instructions on setting up Facebook Connect is probably this wiki page, but it's still a bit murky. Facebook Connect can be used for both completely external sites, or just regular content inside an iframe. You fall into the latter category, so if you follow the instructions in that link and use the first line of code in step 2 (for the FeatureLoader), you should be ok.
Once you've included the FeatureLoader.js script and called FB.init, you should generally be up and running with FB Connect. You should be able to interact with the API from then on out. The users.getLoggedInUser() method will give you the current user id inside the iframe via Javascript.
Hope that helps.
Note that as of March 2011, FB is moving to POST requests to load iframes. It sends a form action with method="post" and target="iframe_canvas", plus an input type="hidden" with a "signed_request"
You cna use the facebook API to get the user ID by calling
Users.getLoggedInUser
You can access that value, then use echo() to add that to your HTML as a javascript variable, which will make it available to your Javascript code.
Try Env.user, it has the logged in user's ID.

Categories