0

我不想使用默认的 fb 分享按钮,所以我创建了一个按钮,用很好的悬停来象征 fb,现在我想将它链接到 fb 分享 api。可以这样做吗?

4

1 回答 1

0

您可以使用 javascript sdk 和提要对话框来做到这一点。只需为您的图像分配一个 onclick 事件,然后调用对话框函数。以下是来自https://developers.facebook.com/docs/reference/dialogs/feed/的片段

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="https://www.facebook.com/2008/fbml">
<head>
 <title>My Feed Dialog Page</title>
 </head>
<body>
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>
<p id='msg'></p>

<script> 
  FB.init({appId: "YOUR_APP_ID", status: true, cookie: true});

  function postToFeed() {

    // calling the API ...
    var obj = {
      method: 'feed',
      link: 'https://developers.facebook.com/docs/reference/dialogs/',
      picture: 'http://fbrell.com/f8.jpg',
      name: 'Facebook Dialogs',
      caption: 'Reference Documentation',
      description: 'Using Dialogs to interact with users.'
    };

    function callback(response) {
      document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
    }

    FB.ui(obj, callback);
  }

</script>

于 2011-09-30T16:17:31.867 回答