its very simple steps
step 1
you have to create one app in face book
create one fb account -> goto developer link in footer part
click -> create new app button .
give all info about you web site.
then they will provide API_Key And API_Secret.
step 2
create one aspx page in your application
step 3
place one button control in your page
c#
use these code in page load event
FaceBookConnect.API_Key = "xxxxxxxxxxxxxxxxxxxxxxxx"; // user your facebook api key
FaceBookConnect.API_Secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
//user your facebook API_Secret
string code = Request.QueryString["code"];
if (!string.IsNullOrEmpty(code))
{
string data = FaceBookConnect.Fetch(code, "me");
FaceBookUser faceBookUser = new JavaScriptSerializer().Deserialize<FaceBookUser>(data);
faceBookUser.PictureUrl = string.Format("https://graph.facebook.com/{0}/picture", faceBookUser.Id);
Session["code"] = code;
Session["Uid"] = faceBookUser.Id;
DataTable ds = b.CheckEmail_signup(faceBookUser.Email);
if (ds.Rows.Count == 0)
{
Int64 intLID = Convert.ToInt64(faceBookUser.Id);
p.v_FName = faceBookUser.first_name;
p.v_Lname = faceBookUser.last_name;
p.v_Email = faceBookUser.Email;
p.v_Photo = faceBookUser.PictureUrl;
p.v_Gender = faceBookUser.gender;
if (b.fbclientinfo_insert(intLID, p.v_FName, p.v_Lname, p.v_Email, p.v_Photo, p.v_Gender, "Approve","True") == "Success")
{
Response.Redirect("home.aspx");
}
}
else
{
Response.Redirect("home.aspx");
}
}
button click event
paste these code
FaceBookConnect.Authorize("user_photos,email", Request.Url.AbsoluteUri.Split('?')[0]);
Create one model like
public class FaceBookUser
{
public string Id { get; set; }
public string first_name { get; set; }
public string last_name { get; set; }
public string PictureUrl { get; set; }
public string Email { get; set; }
public string gender { get; set; }
public string birthday { get; set; }
}
No comments:
Post a Comment