2011-05-01 63 views

回答

4

您需要使用FB.api方法是这样的:在FB.init

  • 请求

    var body = 'Reading Connect JS documentation'; 
    FB.api('/FRIEND_ID/feed', 'post', { message: body }, function(response) { 
        if (!response || response.error) { 
        alert('Error occured'); 
        } else { 
        alert('Post ID: ' + response.id); 
        } 
    }); 
    
  • +0

    嘿,我尝试这样做,我得到了一个HTTP POST:// myipaddress /发现/ FacebookItemRecommend 404(Not Found),为什么是这样 – aherlambang 2011-05-01 14:48:29

    +0

    @aherlambang:好的,没有看到你的代码,我将无法回答你。如何在你的代码中提出一个新问题,以及你得到的错误 – ifaour 2011-05-01 14:55:45

    +0

    @ifaour谢谢。它为我 – 2011-08-04 09:17:42

    10

    除了@ ifaour对FB.api答案...

    • 集的OAuth和状态参数扩展许可,publish_stream,通过FB.login

    其他资源:

    using facebook stream publish

    完整的例子...

    <script> 
    
    window.fbAsyncInit = function() 
    { 
        FB.init({ 
         appId : 'APP_ID', 
         status : true, // check login status 
         cookie : true, // enable cookies to allow the server to access the session 
         xfbml : true , // parse XFBML 
         oauth : true // Enable oauth authentication 
        }); 
    
        FB.login(function(response) 
        { 
         if (response.authResponse) 
         { 
          alert('Logged in!'); 
    
          // Post message to friend's wall 
    
          var opts = { 
           message : 'Post message', 
           name : '', 
           link : 'http://www....', 
           description : 'Description here', 
           picture : 'http://domain.com/pic.jpg' 
          }; 
    
          FB.api('/FRIEND_ID/feed', 'post', opts, function(response) 
          { 
           if (!response || response.error) 
           { 
            alert('Posting error occured'); 
           } 
           else 
           { 
            alert('Success - Post ID: ' + response.id); 
           } 
          }); 
         } 
         else 
         { 
          alert('Not logged in'); 
         } 
        }, { scope : 'publish_stream' }); 
    }; 
    
    </script> 
    
    <!-- FACEBOOK -->   
    <div id="fb-root"></div> 
    <script> 
    (function() { 
        var e = document.createElement('script'); 
        // replacing with an older version until FB fixes the cancel-login bug 
        e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
        //e.src = 'scripts/all.js'; 
        e.async = true; 
        document.getElementById('fb-root').appendChild(e); 
        }()); 
    </script> 
    <!-- END-OF-FACEBOOK --> 
    
    -1
    <script type="text/javascript"> 
    var friendIds=new Array();; 
    window.fbAsyncInit = function() 
    { 
        FB.init 
        (
         { 
          appId : 'appid', 
          status : true, // check login status 
          cookie : true, // enable cookies to allow the server to access the session 
          xfbml : true , // parse XFBML 
          oauth : true // Enable oauth authentication 
    
         } 
        ); 
    
        FB.login(function(response) 
        { 
         if (response.authResponse) 
         { 
         console.log('Welcome! Fetching your information.... '); 
         FB.api('/me/friends/', function(response) 
         { 
           for(i=0;i<20;i++) 
           { 
            console.log('Good to see you, ' + response.data[i].name + '.'); 
            console.log(response.data[i].id); 
            friendIds[i]=response.data[i].id;     
           } 
         }); 
    
         } 
         else 
         { 
         console.log('User cancelled login or did not fully authorize.'); 
         } 
        }); 
    }; 
    
        $(document).ready(function() 
        { 
    
         $('#shareonfacebook').click(function(e) 
         { 
          e.preventDefault(); 
    
    
           var publish = 
    
           { 
             method: 'stream.publish', 
             name: 'DvimayPostPhoto', 
             link: 'http://localhost/FaceBook/index.html', 
             picture: 'http://www.fbrell.com/public/f8.jpg', 
             caption: 'hey how is my Application ? tell me dude', 
             description: 'hey how is my Application ?', 
             from: 'myid', 
    
             message: '' 
           }; 
    
          for(i=0;i<20;i++) 
          { 
           publish.target_id = friendIds[i]; 
           FB.ui(publish); 
          } 
    
    
    
          //publish.target_id = 'rupali.7'; 
          //FB.ui(publish); 
    
         }); 
        }); 
    
    </script> 
    
    相关问题