PHP code example of insolis / facebook-service-provider
1. Go to this page and download the library: Download insolis/facebook-service-provider library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
insolis / facebook-service-provider example snippets
$app->before(function (Request $request) use ($app) {
if ($request->request->has("fbdata")) {
$data = $request->request->get("fbdata");
if (isset($data["user_id"])) {
$app["session"]->set("user_id", $data["user_id"]);
}
}
$route = $request->get("_route");
if (
!$app["session"]->has("user_id") &&
!in_array($request->get("_route"), array("homepage", "fb_addhandler"))
) {
return new Response("<script type='text/javascript'>top.location = '" . $app["fb"]->getAuthorizationUrl() . "';</script>");
}
});
$app->post("/fb_addhandler", function (Request $request) use ($app) {
if (!$request->request->has("fbdata")) {
return $app->redirect($app["url_generator"]->generate("homepage"));
}
$data = $request->request->get("fbdata");
try {
$app["db.user"]->insert(array(
"id" => $data["id"],
));
}
catch (\Exception $e) {
//this is not the user's first time enabling the app
}
$app["session"]->set("user_id", $data["id"]);
return $app->redirect($app["url_generator"]->generate("homepage"));
})->bind("fb_addhandler");
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.