Upload
varun-bihani
View
220
Download
0
Embed Size (px)
Citation preview
8/3/2019 FACEBOOK Development (API) Changes
1/7
FACEBOOK Development (API) Changes
Galaxy Web links Ltd.
349 5th avenue New York
NY 10016, United States
Website: http://www.galaxyweblinks.com
Face book connect guide for all users using face book connect on your site
Face book has updated its code and all users who have face book connect on their
site will need to update the codes to function properly. The techies atGalaxyhave
been prompt in applying the same to all our client sites and are sharing theinformation here which will help the developers at large to update their face book
connect authentication process to keep it in syn with Face book.
Please see below the code modification process explained with examples.
Example Old Method
Example New Method
Example PHP Old Method for getting facebook cookie
functionget_facebook_cookie_old($app_id, $application_secret) {
$args = array();
if(isset($_COOKIE['fbs_' . $app_id]))
parse_str(trim($_COOKIE*'fbs_' . $app_id+, \\), $args);
ksort($args);
$payload = ;
foreach ($args as $key => $value) {
if ($key != sig)
http://www.galaxyweblinks.com/http://www.galaxyweblinks.com/http://www.galaxyweblinks.com/http://www.galaxyweblinks.com/8/3/2019 FACEBOOK Development (API) Changes
2/7
FACEBOOK Development (API) Changes
Galaxy Web links Ltd.
349 5th avenue New York
NY 10016, United States
Website: http://www.galaxyweblinks.com
$payload .= $key . = . $value;
}
}
if(isset($args['sig']))
if (md5($payload . $application_secret) != $args['sig']) {
return null;
}
return $args;
}
Example PHP New Method for getting facebook cookie
functionget_facebook_cookie($app_id, $app_secret) {
$signed_request = ;
if(isset($_COOKIE['fbsr_' . $app_id]))
$signed_request = parse_signed_request($_COOKIE['fbsr_' . $app_id],
$app_secret);
// $signed_request should now have most of the old elements
$signed_request["uid"] = isset($signed_request["user_id"]) ?
$signed_request["user_id"] : NULL; // for compatibility
if (!is_null($signed_request)) {
// the cookie is valid/signed correctly
// lets change code into an access_token
8/3/2019 FACEBOOK Development (API) Changes
3/7
FACEBOOK Development (API) Changes
Galaxy Web links Ltd.
349 5th avenue New York
NY 10016, United States
Website: http://www.galaxyweblinks.com
if(isset($signed_request["code"])) {
$access_token_response =
file_get_contents(https://graph.facebook.com/oauth/access_token?client_id=$a
pp_id&redirect_uri=&client_secret=$app_secret&code=.$signed_req uest["code"
]);
parse_str($access_token_response);
$signed_request["access_token"] = $access_token;
$expires = (60 * 60);
$signed_request["expires"] = time() + $expires;
}
}
return $signed_request;
}
function base64_url_decode($input) {
return base64_decode(strtr($input, -_, /));
}
functionparse_signed_request($signed_request, $secret) {
list($encoded_sig, $payload) = explode(., $signed_request, 2);
// decode the data
$sig = base64_url_decode($encoded_sig);
$data = json_decode(base64_url_decode($payload), true);
8/3/2019 FACEBOOK Development (API) Changes
4/7
FACEBOOK Development (API) Changes
Galaxy Web links Ltd.
349 5th avenue New York
NY 10016, United States
Website: http://www.galaxyweblinks.com
if (strtoupper($data*'algorithm'+) !== HMAC-SHA256) {
error_log(Unknown algorithm. Expected HMAC-SHA256);
return null;
}
// check sig
$expected_sig = hash_hmac(sha256, $payload, $secret, $raw = true);
if ($sig !== $expected_sig) {
error_log(Bad Signed JSON signature!);
return null;
}
return $data;
}
Example Javascript Old Method
FB.init(appId: YOUR_FACEBOOK_API_ID,
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe(auth.login, function(response)
8/3/2019 FACEBOOK Development (API) Changes
5/7
FACEBOOK Development (API) Changes
Galaxy Web links Ltd.
349 5th avenue New York
NY 10016, United States
Website: http://www.galaxyweblinks.com
window.location=PATH_TO_BE_REDIRECT_AFTER_LOGIN;
});
//check facebook login status
FB.getLoginStatus(function(response) {
if (response.session) {
//logged in, force logout
FB.logout(function() {
// If needed
window.location = PATH_TO_BE_REDIRCT_AFTER_LOGOUT;
});
} else {
//not logged in
}
});
Example Javascript New Method
FB.init(appId: YOUR_FACEBOOK_API_ID,
status: true,
cookie: true,
8/3/2019 FACEBOOK Development (API) Changes
6/7
FACEBOOK Development (API) Changes
Galaxy Web links Ltd.
349 5th avenue New York
NY 10016, United States
Website: http://www.galaxyweblinks.com
xfbml: true,
oauth : true
});
FB.Event.subscribe(auth.login, function(response) {
window.location=https://www.facebook.com/dialog/oauth?client_id=YOUR_FAC
EBOOK_API_ID&redirect_uri=PATH_TO_BE_REDIRECT_AFTER_LOGIN&response_t
ype=token;
});
//check facebook login status
FB.getLoginStatus(function(response) {
if(response.authResponse) {
//logged in, force logout
FB.logout(function() {
// If needed
window.location = PATH_TO_BE_REDIRCT_AFTER_LOGOUT;
});
} else {
//not logged in
}
});
8/3/2019 FACEBOOK Development (API) Changes
7/7
FACEBOOK Development (API) Changes
Galaxy Web links Ltd.
349 5th avenue New York
NY 10016, United States
Website: http://www.galaxyweblinks.com
AtGalaxy We blinkswe create custom Face book apps for businesses. Our experts
have strong experience in developing custom Face book applications and
integrate them with websites. For details please visit us at
http://www.galaxyweblinks.com/services/facebook-apps/.
More References:
http://blog.galaxyweblinks.com/2011/12/16/facebook-apps/facebook-connect-
login-problem-an-easy-solution-by-galaxy-weblinks/
https://developers.facebook.com/docs/guides/web/
http://developers.facebook.com/docs/appsonfacebook/tutorial/
https://developers.facebook.com/blog/post/464
http://developers.facebook.com/docs/reference/javascript/
http://www.galaxyweblinks.com/http://www.galaxyweblinks.com/http://www.galaxyweblinks.com/http://www.galaxyweblinks.com/contact-us/http://www.galaxyweblinks.com/contact-us/http://www.galaxyweblinks.com/contact-us/http://www.galaxyweblinks.com/contact-us/http://blog.galaxyweblinks.com/2011/12/16/facebook-apps/facebook-connect-login-problem-an-easy-solution-by-galaxy-weblinks/http://blog.galaxyweblinks.com/2011/12/16/facebook-apps/facebook-connect-login-problem-an-easy-solution-by-galaxy-weblinks/http://blog.galaxyweblinks.com/2011/12/16/facebook-apps/facebook-connect-login-problem-an-easy-solution-by-galaxy-weblinks/https://developers.facebook.com/docs/guides/web/https://developers.facebook.com/docs/guides/web/http://developers.facebook.com/docs/appsonfacebook/tutorial/http://developers.facebook.com/docs/appsonfacebook/tutorial/https://developers.facebook.com/blog/post/464http://developers.facebook.com/docs/reference/javascript/http://developers.facebook.com/docs/reference/javascript/https://developers.facebook.com/blog/post/464http://developers.facebook.com/docs/appsonfacebook/tutorial/https://developers.facebook.com/docs/guides/web/http://blog.galaxyweblinks.com/2011/12/16/facebook-apps/facebook-connect-login-problem-an-easy-solution-by-galaxy-weblinks/http://blog.galaxyweblinks.com/2011/12/16/facebook-apps/facebook-connect-login-problem-an-easy-solution-by-galaxy-weblinks/http://www.galaxyweblinks.com/contact-us/http://www.galaxyweblinks.com/contact-us/http://www.galaxyweblinks.com/