I am building an app with the functionality to publish messages to users walls while specific actions runs on my website.
What I have done is (briefly):
Registered my own app on Facebook
Added a login button on my website with permission to publ开发者_开发技巧ish:
Log in on Facebook
- Downloaded facebook-php-sdk library
It is now I start having problems. I do not know how to do what I want to do now.
What I want to do:
When a user logs on to facebook via my website. I want a file on my site to be called, where I can update the user's data in my own database as well.
Because that is not what the canvas url is meant to do? How it is no, seems no file at all is called on my site when I click on Login.
Since you are using the Facebook PHP-SDK you noticed that there are two options for the users to login:
- Using the XFBML button, which will:
- Open a login dialog (pop-up) asking for permissions..etc
- When a successful authentication/authorization is complete the dialog will close, the
auth.login
event will be triggered and based on that the page will get reloadedwindow.location.reload();
- The PHP in the top of the page will get into business and
$session = $facebook->getSession();
will actually retrieve a session!$user = $facebook->getUser();
will retrieve the current user
- Using the Login URL generated by the Library
$loginUrl = $facebook->getLoginUrl();
this URL will get you through the same flow and if you noticed there's anext
redirect_uri
parameter which will redirect you back after a successful process to that URL (mainly the same URL you are at), where you can change that parameter if you like.
The canvas URL is the URL Facebook uses when it displays your application from within Facebook. You would use this functionality if you expect users to use your application while in Facebook itself.
When authenticating using Facebook's API (assuming graph API usage here), you provide a redirect_uri as part of the authentication URL. Once Facebook has authorized your application, it will redirect the user's web browser to the URI you specified. This URI can be any link you desire on your site. You should use the link as the determination of when the user is logged in successfully, e.g., https://mywebsite/facebook/loggedin.
精彩评论