using ASPSnippets.FaceBookAPI;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class testingfacebook : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
FaceBookConnect.API_Key = ConfigurationManager.AppSettings["1521040144856517"];
FaceBookConnect.API_Secret = ConfigurationManager.AppSettings["f306282212453f2f294bcac760096fc"];
if (!IsPostBack)
{
if (Request.QueryString["login"] == "1")
{
FaceBookConnect.Authorize("publish_actions", Request.Url.AbsoluteUri.Split('?')[0]);
return;
}
if (Request.QueryString["code"] != null)
{
Session["Code"] = Request.QueryString["code"];
ClientScript.RegisterStartupScript(GetType(), "script", "window.opener.location.reload(); window.close();", true);
return;
}
if (Session["Code"] != null)
{
imgFaceBook.AlternateText = "share";
imgFaceBook.ImageUrl = "~/img/fbshare.png";
}
LoadImages();
}
}
protected void ShareImage(object sender, EventArgs e)
{
string imageUrl = Request.Form["image_url"];
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("link", imageUrl);
data.Add("picture", imageUrl);
FaceBookConnect.Post(Session["Code"].ToString(), "me/feed", data);
ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Image has been shared.');", true);
}
private void LoadImages()
{
DataTable dt = new DataTable();
dt.Columns.Add("ImageUrl", typeof(string));
dt.Rows.Add("http://farm4.staticflickr.com/3792/9147205860_5da6951bf4_m.jpg");
dt.Rows.Add("http://farm9.staticflickr.com/8380/8474516903_8a5eb01b51_m.jpg");
dt.Rows.Add("http://farm9.staticflickr.com/8395/8985239089_4318196db2_m.jpg");
dt.Rows.Add("http://farm4.staticflickr.com/3723/8986453414_a869ddc3aa_m.jpg");
this.dlImages.DataSource = dt;
this.dlImages.DataBind();
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="testingfacebook.aspx.cs" Inherits="testingfacebook" %>
<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" Runat="Server">
<style type="text/css">
.info
{
background-color: black;
filter: alpha(opacity=80);
opacity: 0.8;
position: absolute;
display: block;
text-align: center;
}
.info input
{
position: relative;
top: 35px;
}
</style>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
var info = $(".info");
$(".picture").bind("mouseenter", function () {
var p = GetScreenCordinates(this);
$("input", info).attr("rel", this.src);
info.show();
info.css("height", $(this)[0].offsetHeight / 2);
info.css("width", $(this).width());
info.css({ "left": p.x, "top": p.y + this.offsetHeight - info[0].offsetHeight });
});
$(".info a, .info").bind("mouseenter, mousemove, mouseover", function () {
info.show();
});
$(".picture").bind("mouseleave", function () {
info.hide();
});
$("[id*=imgFaceBook]").bind("click", function () {
if (this.alt == "login") {
window.open("testingfacebook.aspx?login=1", "LoginPopup", "width=550,height=300,resizable=1");
return false;
}
var hidden = $("<input name = 'image_url' type = 'hidden' />");
hidden.val($(this).attr("rel"));
$("form").append(hidden);
});
});
function GetScreenCordinates(obj) {
var p = {};
p.x = obj.offsetLeft;
p.y = obj.offsetTop;
while (obj.offsetParent) {
p.x = p.x + obj.offsetParent.offsetLeft;
p.y = p.y + obj.offsetParent.offsetTop;
if (obj == document.getElementsByTagName("body")[0]) {
break;
}
else {
obj = obj.offsetParent;
}
}
return p;
}
</script>
<asp:ListView ID="dlImages" runat="server">
<ItemTemplate>
<img src="<%#Eval("ImageUrl") %>" class="picture" alt="" height="200" width="200" />
</ItemTemplate>
</asp:ListView>
<div class="info" style="display: none">
<asp:ImageButton ID="imgFaceBook" AlternateText="login" ImageUrl="~/img/fbLogin.jpg"
runat="server" OnClick="ShareImage"></asp:ImageButton>
</div>
</asp:Content>