我可以使用Facebook的API来“添加好友”吗?

31

他们的API允许我的Facebook连接用户添加好友吗?

4个回答

29

不可以通过API添加好友。

但是,您可以将用户直接引导到http://www.facebook.com/addfriend.php?id=[USER UID]

其中[USER UID]是有效的Facebook用户ID。

祝好运!


4
现在有一种方法。参考somethingkindawierd的回答。 - Gdeglin
实际上,@mattdipasquale的回答就是如何操作的。@somethingkindawierd的回答已经过时了。 - ma11hew28

28

我花了很多时间寻找,最终找到了一个非常简单的解决方案。

使用Facebook Javascript API,您可以发送好友请求:

<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>

回调脚本可以通过ajax调用您的服务器,在那里保存有关操作的信息(如果需要)。

您可以使用Facebook上的javascript控制台应用程序进行测试:

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

将上面的脚本粘贴进来,包括标签,或者点击文本区域底部的“示例”按钮,找到“fb.ui-friends.add”示例。

3
我们使用了这个解决方案相当长的一段时间。可惜的是,随着Facebook Graph API的2.0版本,这个解决方案被弃用了。(它不再可用)我没有其他替代方法的建议。 - rinogo

1

这个能在IOS应用程序中使用吗? - John
4
链接网站现在显示:"此功能已自图形API版本2.0起被移除"。 - Joseph Lord

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接