0

我正在尝试将 facebook 的 javascript sdk 与 salesforce 集成。我遵循了链接上给出的所有说明:http: //developers.facebook.com/docs/howtos/login/getting-started/ 但我无法登录。我在 facebook 开发人员控制台中复制粘贴的相同代码,它工作正常。现在我很困惑,在与 salesforce 集成时我是否遗漏了一些东西,或者 salesforce 不支持 facebook 的 javascript sdk?

4

1 回答 1

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>
于 2013-04-04T14:43:14.883 回答