开发者

linking facebook share api to a button image

开发者 https://www.devze.com 2023-04-10 07:40 出处:网络
i don\'t want to use the default fb share button so I\'ve created a button that symbolizes fb with nice hover, now i wa开发者_如何学运维nt to link it to the fb share api.is it possible to do that?You

i don't want to use the default fb share button so I've created a button that symbolizes fb with nice hover, now i wa开发者_如何学运维nt to link it to the fb share api.is it possible to do that?


You can do that using the javascript sdk and the feed dialog. Just assign your image an onclick event and then call the dialog function. Below is the snippet from 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>

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号