简体   繁体   English

如何使用fb.api保存画布图像并共享到Facebook

[英]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. 我想将画布图像保存到文件夹并在登录的用户墙上的Facebook中共享它,我正在使用html2canvas插件,但是我的问题是div元素未在画布中绘制,div中的数据来自数据库,如下所示我写的代码。

HtmlCode: 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: JavaScript代码:

  $(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. 第一件事是您必须将画布图像保存在要共享它的域上,因为您的facebook应用程序仅支持一个。 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 文档在这里。希望有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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