Can I “add friend” with Facebook's API?

前端 未结 4 773
感动是毒
感动是毒 2020-12-07 17:34

Does their API allow my Facebook-connected user to add a friend?

相关标签:
4条回答
  • 2020-12-07 17:41

    Here is a Wiki list of the API methods available to you http://wiki.developers.facebook.com/index.php/API#Administrative_Methods

    Doesn't look like you can add friends via the API. Note the iPhone facebook app also doesn't have an add friends function, it was written via the API, so that lends more weight to the idea that you can't

    0 讨论(0)
  • 2020-12-07 17:42

    I spent a great deal of time looking, and finally came accross a very simple solution.

    Using the Facebook Javascript API you can do a friend request with:

    <script>
        FB.ui(
         { 
          method: 'friends.add', 
          id: fbid // assuming you set this variable previously...
         }, 
         function(param){
    
          console.log(param);
    
                // If they cancel params will show: 
                //    {action:false, ...}
                // and if they send the friend request it'll have:
                //    {action:true, ...}
                // and if they closed the pop-up window then:
                //    param is undefined
         }
        );
    </script>
    

    The callback script can then simply performs an ajax call to your server where you save info about the action, if needed.

    You can test this by using the javascript console app on Facebook:

    http://developers.facebook.com/tools/console

    Paste in the script above, including the tags, or click the "Examples" button on the bottom of the text area and find the "fb.ui — friends.add" example.

    0 讨论(0)
  • 2020-12-07 17:44

    No. Adding friends is not possible through the API.

    However you can direct users to http://www.facebook.com/addfriend.php?id=[USER UID]

    Where [USER UID] is a valid facebook user id.

    Good luck!

    0 讨论(0)
  • 2020-12-07 18:08

    https://developers.facebook.com/docs/reference/dialogs/friends/

    0 讨论(0)
提交回复
热议问题