I have a fair amount of Facebook development experience, but this had made me pull my hair. It must be something very small, but I can't get it. I recently saw some Facebook pages with welcome tabs that show user's name "Welcome [YOUR NAME]" who visits their page. Example is here:
https://www.facebook.com/Tony.Samaha.Official.Page
As per my knowledge, we cannot get the user id without the permissions by the user. After the permissions we are able to get the user id in the signed request. How do I get the Facebook user id or name, something similar to the above example? How is this working? Can this be achieved?
FYI: I am using iframe tab.
Check out the documentation on signed_requests. When a user visits your application there will be a signed_request posted to your URL. The documentation states :
A signed_request is passed to Apps on Facebook.com when they are
loaded into the Facebook environment
A signed_request is passed to any
app that has registered an Deauthorized Callback in the Developer App
whenever a given user removes the app using the App Dashboard
A signed_request is passed to apps that use the Registration Plugin
whenever a user successfully registers with their app
You will have to decode this request (see the link above for details) and from there you will be able to extract the user_id of the visiting user. Then all you have to do is query the Graph API like this :
https://graph.facebook.com/USER_ID and you will get back the public information for that user which should include the users name.
The user is still using the old static FBML application, so most likely they are using the fb:name tag. Though, I believe this is now deprecated. So really, the page you linked to needs to be updated.
Related
I like a create a simple web blog (written in PHP), to satisfy my blog's audiences, he/she should only have to register to my blog once (using his/her Facebook user account), after then he/she wouldn't need to re-login to my blog again in the future
There are steps I can think of
User visit the login link created using new FacebookRedirectLoginHelper($facebook_redirect_url); just as in SDK's documentation
After the login process, my blog then create facebook session using $helper->getSessionFromRedirect(); to access the Graph API to access user's public information, e.g. email, profile name, profile picture, etc.
My blog then store all user's public info into the blog's database
My blog then write his/her facebook ID to the cookies
For the next visits, my blog just has to use the facebook ID which comes with the cookies to authenticate into my blog
I think the above steps seem to meet my requirement, but if there is any suggestions please give me some ideas to improve
I wouldn't need the blog user to re-login ever again because I have all information I need in the blog's database, but the question is what to do to let my app get up-to-date information of the user (e.g. profile's picture, etc) I cannot use his/her access token to access the graph API anymore because it will always become expired
Please guide me some ideas for the solution
P.S. The most important requirement is to offer single registration & login to the blog's user, unless he/she manually logout
Thanks.
You can get the public information of any user if you have their facebook id or user name. For example you can get my public details using the below code:
https://graph.facebook.com/AbdulAzeez86
Here you can change username with id, which you will keep in your database.
To get the profile picture of a user you can use the below code:
https://graph.facebook.com/AbdulAzeez86/picture?type=large
Here also you can change name with id and type with any of these (square,small,normal,large)
To get the contents you can use curl ,file_get_contents etc.
Firstly I am aware that there are a million questions similar to this, but they are all either out of date (Facebook has changed and the instructions no longer work) or don't explain how to do specifically what I am asking.
I'm trying to register an app on Facebook so that I can autopost to the company Facebook page, of which I am an admin.
I'm trying to do this via PHP, with which I have considerable experience (PHP, not Facebook API.)
So far I have registered as a Facebook developer, made a Facebook app, got the appID and secret word, and downloaded the facebook-php-sdk from Github. I have attempted to follow a couple of tutorials but the Facebook developer/app pages have all changed and so the intructions are now invalid.
All I want to do is to be able to post automatically to my page's wall from the server via PHP, as if I posted the status update myself as the page admin. I don't understand how or why this is so difficult.
The Facebook app page has a million settings that I've never heard of and don't seem to be related, then there is no information that gives any direction to do what I want to do.
This is about as far as I've got and I've hit a wall. No idea what to do next. Facebook keeps asking me "Select how your app integrates with Facebook" but their options don't appear to include what I want, which is just to post on my own page. I don't appear to actually be able to use the app yet, as there are various settings its insisting on, like "Canvas URL", which I do not understand, etc. and then I obviously need to set permissions, yet I see no way to do this either.
What do I do?
Setting up an app
You are going to need to authenticate the user who has at least content creator rights on your page. So you need to choose 'Website with Facebook Login' and enter your website url.
You'll also have to enter the domain (website url without protocol)
Keep it in sandbox mode while you test it you can edit that later.
You don't really have to worry about other settings as the permissions to ask can be added directly in your php code.
"Online" Access
To logging and post directly to facebook you'll need to retreive an access token
Getting an access token
Here is a basic run down:
Get user to login and allow app with appropriate permissions (manage_pages, publish_stream) if he hasn't
Retreive user access token
Query /me/accounts with user access token to get the page id & access token
Then all you have to do is make your API call with id & access token to post on facebook
"Offline" Access
In order to post without having to logging (usefull if you aren't the only one posting) you need a permanent extended token. So you basically should have a separate script that you'll run once to retrieve that extended token and store it.
Getting an extended access token
To be able to post without the user being logged in you need a permanent access token for your page.
Here is a basic run down:
Get user to allow app with appropriate permissions (manage_pages, publish_stream)
Retreive user access token
Change user access token for extended user access token
Here is how I do this step (you could also use curl)
$token_url = "https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUT_APP_SECRET&grant_type=fb_exchange_token&fb_exchange_token=OLD_TOKEN";
$accessToken = #file_get_contents($token_url);
Then
Query /me/accounts with user extended access token to get the page
Change page access token for extended access token (same code as
above)
(The last step shouldn't be necessary according to the doc as you should get an extended page token when you query /me/accounts with an extended user token but in my case it didn't work)
And you get a permanent access token that only expires if the user changes password or disallows the app. All you have to do is store it with the page's id and retreive it wherever you need an API call to post to facebook.
The php sdk is pretty well documented so you shouldn't run into any problem a google search can't fix. Look for post september 2012 threads the flow hasn't changed since neither did the php sdk much.
I need implement a functionality in save/update function, of my customers system:
In each save/update, I need get this informations, and send to a Facebook Page (every the same Page).
But my problem is: this system is used by a lot users, and some users do not have a Facebook account, so: How can I post in same Page without login?
I know the offline_access are removed, so, what the best solution in this situation?
I don't find any way, to get the Page Access Token
I create some APP in my personal account of Facebook, but, when I try post in this Page, I get a access unauthorized for this user/app
Sorry for my english.
For you to post updates on to the Page's feed there are few things you would require
An User with administrative or content publishing permission to atuhorize your application with manage_pages Extended permissions. If you have implemented the login, you can add these permissions there, or alternatively you can use Graph Explorer with your application selected to get started.
After you have been authorized then you can retrieve the Page Access Token by querying /me/accounts which would return data as shown in this documentation. You can then utilize the access token you retrieve for the corresponding page to do your job of posting updates.
I downloaded the Facebook-sdk for php and played around with it for a while.
So they have this example file, where user info is showed:
facebook-facebook-php-sdk-98f2be1/examples/example.php
It only shows user info after accepting the app.
Maybe that's not even possible/allowed...
But I what to know if a user is logged into facebook, not into my app.
I don't need his name, id, etc, nothing... Just want to know IF he there is a Facebook session in the background. Reason: I want to redirect users who are not logged in to Facebook elsewhere, because maybe they don't even have a facebook account.
But I w[an]t to know if a user is logged into facebook, not into my app. […] Just want to know IF he there is a Facebook session in the background.
That’s not possible.
Without having a user connect to our app first, you get virtually nothing, no info whatsoever.
Update:
The PHP SDK now has a method getLoginStatusUrl that can provide that info.
It can determine three different states – a user logged into Facebook, logged out of Facebook, or unknown. It works by redirecting the user’s browser to Facebook to make the check, and then redirecting to three different URLs of your app that you can specify.
(Of course this’ll work without using the PHP SDK as well – you will just have to look into it’s source to see what the exact URL it creates is, then you can redirect the user there yourself.)
First of all, thanks in advance for reading. I've already posted this question in the facebook forums but after a couple of hours I'm not getting any responses.
I've got this app where an user can choose a piece (like in a puzzle). After the user picks a piece, he is redirected to the facebook authorize page and then returned to the app, then I save the user ID and his chosen piece in the database. At this point I've got everything alright... but the problem comes when...
If anyone see the app, he should be able to see the pieces and the PIECES OWNER INFO (name and profile picture).
The problem is if the user has not allowed the app yet (facebook authorization page), I can't use the facebook API to get the users who have already allowed the app (because I need an access token and the access token is given only to users who has authorized the app).
So, in short:
I need: get name and profile picture of users who have already authorized the app, without authenticating all users.
P.S: I was trying the "Authenticating as an App" option with PHP+libCURL but didn't work (or I did it the wrong way).
P.S2: Sorry if I have writing mistakes, my speaking language is spanish.
Thanks again... A LOT!!!!
No authentication nor breach of TOS required if you have the IDs, as profile pic and name are public information
Proof?? Right Here in this JSON.