Javascript Facebook Opengraph 自定义 Facebook 登录按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3701972/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook Opengraph customize fb login button
提问by diegueus9
I'm using facebook open graph, new api, and i can do this:
我正在使用 facebook open graph、new api,我可以这样做:
<fb:login-button show-faces="true" max-rows="9" perms="email" autologoutlink="true" onlogin="window.location = 'http://www.example.com/facebook/facebook_test/'"></fb:login-button>
but when i read the doc if i need more options in http://developers.facebook.com/docs/reference/javascript/FB.loginsays i can:
但是当我阅读文档时,如果我需要更多选项http://developers.facebook.com/docs/reference/javascript/FB.login说我可以:
FB.login(function(response) {
if (response.session) {
if (response.perms) {
// user is logged in and granted some permissions.
// perms is a comma separated list of granted permissions
} else {
// user is logged in, but did not grant any permissions
}
} else {
// user is not logged in
}
}, {perms:'read_stream,publish_stream,offline_access'});
but if i need another image for fb button, and if i need another things, i can't find how do that, of in what part of html i can call FB.login, is between tags 'script'?
但是如果我需要另一个用于 fb 按钮的图像,如果我需要其他东西,我无法找到如何做到这一点,在 html 的哪一部分我可以调用 FB.login,在标签“脚本”之间?
回答by serg
You need to use Javascript SDKfor this. Just wrap that FB.logininto some function and call it wherever you want. For example if you want to call it on image click:
为此,您需要使用Javascript SDK。只需将它包装FB.login到某个函数中,然后在任何你想要的地方调用它。例如,如果您想在图像单击时调用它:
<html>
<head>
</head>
<body>
<div id="fb-root"></div>
<script>
//initializing API
window.fbAsyncInit = function() {
FB.init({appId: 'your app id', status: true, cookie: true,
xfbml: true});
};
(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>
<!-- custom login button -->
<a href="#" onclick="fblogin();return false;"><img src="images/my_login.png"></a>
<script>
//your fb login function
function fblogin() {
FB.login(function(response) {
//...
}, {scope:'read_stream,publish_stream,offline_access'});
}
</script>
</body>
</html>

