简体   繁体   中英

how to save canvas image and share to facebook using fb.api

i want to save canvas image to folder and share that in facebook on wall of the user logged i'm using html2canvas plugin but my issue is the div element is not getting drawn in the canvas the data in the div is coming from database following is the code i have written.

HtmlCode:

<div class="fan_wrap">
         <ul class="fan_list">
                <% foreach (ProfileDetails currentFollowers in AllFollowers)
                  {
                  %>
  <li <%if (currentFollowers.ID != 0) { Response.Write("class=\"locate\""); } %>>
  <img src="<%=currentFollowers.ProfileImg %>" alt="<%=currentFollowers.Name %>" title="<%=currentFollowers.Name %>" />
   <div class="frame"></div>
     </li>
     <%} %>
   </ul>
    <div class="clearfix"></div>
    <div class="logo_water_mark">
    <img src="images/trans_logo.png" alt="" />
     </div>
    </div>

Javascript Code:

  $(document).ready(function () {
      $('#share_lnk').on('click',function () {
            html2canvas($('.fan_wrap'), {
                onrendered: function (canvas) {
                   var image = canvas.toDataURL("image/jpeg");
                    var url = canvas.toDataURL("image/jpeg");
                    image = image.replace('data:image/jpeg;base64,', '');
                    $.ajax({

                        type: 'POST',
                        url: 'FacebookLogin.aspx/UploadImage',
                        data: '{ "imageData" : "' + image + '" }',
                        contentType: 'application/json; charset=utf-8',
                        dataType: 'json',
                        success: function (msg) {
                            alert('Image saved successfully !');
                        }
                    });
                    var newImg = document.createElement("img");
                    newImg.src = url;
                    document.body.appendChild(newImg);
                }
            });
        });
    });

First thing is that you have to save the canvas image on the domain from where you want to share it as your facebook app supports only one. next you can share the url of the pic to be sharer like below:

FB.ui({
                                method: 'feed',
                                name: "some name",
                                link: "somelink.com",
                                picture: urltobeshared,
                                caption: 'some caption',
                                description: "some descrtiption",
                              },
                              function(response) {
                                if (response && response.post_id) {
                                  console.log('Thank you');
                                }                  
                              }
                        );
                    },

docs are here .Hope that helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM