gpt4 book ai didi

facebook - 自定义 Facebook 连接按钮

转载 作者:行者123 更新时间:2023-12-02 22:38:52 26 4
gpt4 key购买 nike

如何将生成的 Facebook 登录按钮替换为我自己的自定义按钮?

我猜这可以通过创建一个启动对话框的代码函数或使用一些 CSS 技巧将按钮从屏幕上移开来完成。我更喜欢第一个解决方案。

我怎样才能让我自己的按钮做他们做的事并摆脱默认按钮?

这是来自 facebook 开发者网站的示例代码:

require 'fb/facebook.php';

$facebook = new Facebook(array(
'appId' => 'X',
'secret' => 'X',
));

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$user_profile = $facebook->api('/me');
} catch (FacebookApiException $e) {
echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
$user = null;
}
}

?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
<body>
<?php if ($user) { ?>
Your user profile is
<pre>
<?php print htmlspecialchars(print_r($user_profile, true)) ?>
</pre>
<?php } else { ?>
<fb:login-button></fb:login-button>
<?php } ?>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '<?php echo $facebook->getAppID() ?>',
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.login', function(response) {
window.location.reload();
});
FB.Event.subscribe('auth.logout', function(response) {
window.location.reload();
});
};

(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());

</script>
</body>
</html>

最佳答案

只需使用JavaScript SDK的FB.login方法,并在您自己的按钮上调用它。

http://developers.facebook.com/docs/reference/javascript/FB.login/

关于facebook - 自定义 Facebook 连接按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11037191/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com