我们能否将facebook的javascript sdk与salesforce整合在一起?

问题描述:

我正在尝试为facebook与salesforce集成javascript sdk。我遵循链接上给出的所有说明:http://developers.facebook.com/docs/howtos/login/getting-started/ 但我无法登录。我复制粘贴在Facebook开发人员的CONSOL相同的代码,它工作正常。现在我很困惑,我是否错过了一些与salesforce或salesforce的集成不支持Facebook的Facebook的SDK?我们能否将facebook的javascript sdk与salesforce整合在一起?

用下面的代码创建一个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> 
+0

感谢您的回复。我尝试了你的代码,但它给出的错误为: 给定的URL不被应用程序配置所允许:一个或多个给定的URL不被应用程序的设置所允许。它必须与网站网址或Canvas网址匹配,或者该网域必须是其中一个应用网域的子网域。 – Archana 2013-04-05 06:19:20

+0

我错过了什么吗?由于开发者控制台上运行的代码相同,这意味着url是正确的 – Archana 2013-04-05 06:28:16

+0

我在开头添加了