最后,我不得不创建一个小解决方法。通过对所有登录使用指定的登录脚本,我能够将用户重定向回引用页面。
此 Facebook 链接重定向到http://mydomain.de/fb_connect/1/
https://www.facebook.com/dialog/oauth?client_id=[your_app_id]&redirect_uri=http%3A%2F%2F[your_domain]`%2Ffb_connect%2F[domain_id]%2F&state=[some_hash]&scope=email
[your_app_id] = Facebook 应用程序 ID
[your_domain] = www.domain.com 或任何您的域
[domain_id] = 我用它来知道用户来自哪里
[some_hash] = Facebook 用来防止 xsrf
然后我准备了一点 PHP 脚本来使用 apaches mod_rewrite 处理传入的数据
我服务器上 fb_connect 文件夹中的 .htaccess
RewriteEngine On
RewriteRule . index.php [L]
在 index.php 中我使用了类似的东西
<?php
/* App-Id / Secret */
$sAppId = '1234567890';
$sAppSecret = 'sdafuh347890oqtgfuasd';
/* Domains and IDs */
$aDomains = array(
'www.domain.de' => 1,
'www.domain-name.de' => 2,
...
);
/* Save a flipped copy */
$aFlip = array_flip($aDomains);
/* Save the request uri */
$sUri = $_SERVER['REQUEST_URI'];
/* Explode the uri; facebook adds everything after the '?' */
$aParts = explode('?', $sUri);
/* Save the first part */
$sUri = $aParts[0];
/* Explode using slash */
$aParts = explode('/', $sUri);
/* This position should be the domain-id */
$iDomainId = $aParts[2];
/* get the domain name */
$sDomain = $aFlip[$iDomainId];
/* If the user authorizes the app this parameter is set */
if (!empty($_GET['code'])) {
/*
* The redirect uri is needed as a security parameter and needs to be EXACTLY
* like in the refereing URI above
*/
$sRedirectUri = 'http://www.domain.de/fb_connect/' . $iDomainId . '/';
/* Get the access token url for the user */
$sTokenUrl = 'https://graph.facebook.com/oauth/access_token?'
. 'client_id=' . $sAppId
. '&client_secret=' . $sAppSecret
. '&redirect_uri=' . urlencode($sRedirectUri)
. '&code=' . $_GET['code'];
/* Use CURL because file_get_contents() can't handle the length of the uri */
$ch = curl_init();
/* Url */
curl_setopt($ch, CURLOPT_URL, $sTokenUrl);
/* Header */
curl_setopt($ch, CURLOPT_HEADER, 0);
/* Return the response instead of echoing it */
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
/* Exec the request */
$sResponse = curl_exec($ch);
/* close CURL */
curl_close($ch);
/* Initialize the Array for the returned data */
$aParams = array();
/* From the Facebook tutorial ;D */
parse_str($sResponse, $aParams);
/* Build the URI to query the opengraph with a user token */
$sGraphUrl =
'https://graph.facebook.com/me?access_token=' . $aParams['access_token'];
/* get, decode and save the returned values */
$aUser = (array)json_decode(file_get_contents($sGraphUrl));
// You should now have the requested userdata and use it to create an account
// or whatever ;D
/* Redirect the user to the refering domain */
header('Location: http://' . $sDomain);
die;
}
/*
* If the user doesn't authorize the app, this parameter is set.
* Do whatever is needed here (logging, crying...) and redirect the user somewhere ;D
*/
if (!empty($_GET['error'])) {
header('Location: http://' . $sDomain);
die;
}
/*
* If the user deletes the app using the control panel in facebook, your script will
* recieve a ping containging this parameter. This is pretty much the same as if
* your app would run inside the facebook canvas.
*/
if (!empty($_POST['signed_request'])) {
// Decode the signed request using the facebook tutorial methods, and delete
// the user from your system :D
}
?>
这对我来说几乎是诀窍。如果您有任何问题随时问。
问候