Reputation: 1325
I'm trying to use Facebook share button on a list of photos where each photo has its own button with a different URL. Unfortunately I can't make this work. I get all the testing strings except the facebook button string. To test whether the facebook SDK works I removed the string from the webmethod and add it directly on my aspx page. Then it worked! But I want to have it in the Webmethod as follows...
page.aspx (in the body section)
<div id="fb-root"></div>
<script>
(function (d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) return;
js = d.createElement(s); js.id = id;
js.src= "//connect.facebook.net/fr_FR/sdk.js#xfbml=1&appId=**************&version=v2.0";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>
[WebMethod]
public static string photo()
{
StringBuilder photo_sb = new StringBuilder();
var photo_query = db.Query("SELECT * FROM [photos]);
foreach (var item in photo_query )
{
photo_sb.Append("Testing"); // I get this string
photo_sb.Append("<div class=\"fb-share-button\" data-href=\"http://********.com/photos.aspx?IDphoto=" + item.IDphoto + "\" data-layout=\"icon\"></div><br />"); // I don't get this string
photo_sb.Append("Testing2"); // I get this string
}
return photo_sb.ToString();
}
Script
function Load() {
$.ajax({
type: "POST",
url: "UserControls.aspx/photo",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) { if (data.d != "") { $('.photoList').append(data.d);}
...
Upvotes: 0
Views: 369
Reputation: 143
Use the following code to Share
<iframe src="//www.facebook.com/plugins/share_button.php?href=https%3A%2F%2Fdevelopers.facebook.com%2Fdocs%2Fplugins%2F&layout=button_count" scrolling="no" frameborder="0" style="border:none; overflow:hidden;" allowTransparency="true"></iframe>
and to sepcify
<meta property="og:title" content="YOUR TITLE HERE" />
<meta property="og:description" content="YOUR DESCRIPTION HERE" />
<meta property="og:image" content="YOUR THUMBNAIL URL HERE" />
Upvotes: 1