我正在尝试将facebook的javascript sdk与salesforce集成。我按照链接上的所有说明进行了操作:http://developers.facebook.com/docs/howtos/login/getting-started/ 但我无法登录我在facebook开发者consol中复制粘贴相同的代码,它工作正常。现在我很困惑,我在与salesforce或salesforce集成时错过了什么,不支持facebook的javascript sdk?
答案 0 :(得分:1)
使用以下代码创建VF页面。在下面的页面中插入您的应用ID,您应该很高兴。我在静态资源中添加了sdk。
<apex:page >
<div id="fb-root"></div>
<script type="text/javascript" src="/resource/jQueryLatest"></script>
<script>
var j$ = jQuery.noConflict();
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'yourappId', // App ID from the App Dashboard
channelUrl : '/resource/alljs', // Channel File for x-domain communication--- added the sdk in static resource.
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK's source Asynchronously
// Note that the debug version is being actively developed and might
// contain some type checks that are overly strict.
// Please report such bugs using the bugs tool.
(function(d, debug){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all" + (debug ? "/debug" : "") + ".js";
ref.parentNode.insertBefore(js, ref);
}(document, /*debug*/ false));
j$(document).ready(function(){
j$("#loginButton").click(function(){
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name+ '.');
});
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
});
j$("#getAllFriends").click(function(){
FB.api('me/friends', function(response){
// console.log('the response ' + response.data[]);
for(var i =0; i< response.data.length;i++){
try{
var html = '<div>'+ response.data[i].name +' </div>';
j$("#jsonDiv").append(html);
}catch(e){
console.log('error name ' +response.data[i-1].name);
console.log('error ---' + e);
}
}
});
});
});
</script>
<input type="button" id="loginButton" value="login to FB"></input>
<input type="button" id="getAllFriends" value="Get Friends"></input>
<div id="jsonDiv"></div>
</apex:page>