protected void Page_Load(object sender, EventArgs e) { FacebookConnect fbConnect = new FacebookConnect(); if (fbConnect.IsConnected) { Facebook.FacebookAPI api = new Facebook.FacebookAPI(fbConnect.AccessToken); JSONObject me = api.Get("/" + fbConnect.UserID); facebookName = me.Dictionary["name"].String; lblInfo.Text = "Hello " + facebookName + "<br>" + "<br>"; JSONObject f = api.Get("/me/friends"); KeyValuePair<String, JSONObject> friends = f.Dictionary.ElementAt(0); for (int i = 0; i < friends.Value.Array.Count(); i++) { lblFriends.Text = lblFriends.Text + "Friend #" + i.ToString() + " | "; JSONObject friend = api.Get("/" + friends.Value.Array[i].Dictionary["id"].String); lblFriends.Text = lblFriends.Text + friend.Dictionary["name"].String + ", "; lblFriends.Text = lblFriends.Text + friend.Dictionary["link"].String; lblFriends.Text = lblFriends.Text + "<br>"; } } else lblInfo.Text = "Please Login First!"; }
protected void Page_Load(object sender, EventArgs e) { FacebookConnect fbConnect = new FacebookConnect(); if (fbConnect.IsConnected) { Facebook.FacebookAPI api = new Facebook.FacebookAPI(fbConnect.AccessToken); JSONObject me = api.Get("/" + fbConnect.UserID); facebookName = me.Dictionary["name"].String; lblName.Text = "Hello " + facebookName; } }
static void Main(string[] args) { // Get an access token in some manner. // By default you can only get public info. string token = null; Facebook.FacebookAPI api = new Facebook.FacebookAPI(token); JSONObject me = api.Get("/4"); Console.WriteLine(me.Dictionary["name"].String); }
protected void Page_Load(object sender, EventArgs e) { FacebookConnect fbConnect = new FacebookConnect(); if (fbConnect.IsConnected) { Facebook.FacebookAPI api = new Facebook.FacebookAPI(fbConnect.AccessToken); JSONObject me = api.Get("/" + fbConnect.UserID); facebookName = me.Dictionary["name"].String; } else lblInfo.Text = "Please Login First!"; }
protected void Page_Load(object sender, EventArgs e) { string token = this.Request["accessToken"]; string uid = this.Request["uid"]; try { FacebookAPI fb = new FacebookAPI(token); var json = fb.Get("/me"); initParams_SL.Attributes["value"] = "viewMode=facebook,uid=" + json.Dictionary["id"].String + ",firstName=" + json.Dictionary["first_name"].String; string photo = fb.GetImageLocation("/me/picture", null); initParams_SL.Attributes["value"] += ",photo=" + photo; } catch (Exception ex) { } }
// // POST: /Account/LoginWithFacebook public ActionResult ReturnFromFacebook() { string code = Request.QueryString["code"]; if (code == null) { return(RedirectToAction("Home", "Home")); } string AccessToken = ""; try { if (code != null) { string str = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri=http://{1}/Account/ReturnFromFacebook&client_secret={2}&code={3}", System.Web.Configuration.WebConfigurationManager.AppSettings["facebookAppId"], Request.Url.Authority, System.Web.Configuration.WebConfigurationManager.AppSettings["facebookAppSecret"], code); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(str); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; byte[] Param = Request.BinaryRead(System.Web.HttpContext.Current.Request.ContentLength); string strRequest = System.Text.Encoding.ASCII.GetString(Param); req.ContentLength = strRequest.Length; StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); streamOut.Write(strRequest); streamOut.Close(); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); if (strResponse.Contains("&expires")) { strResponse = strResponse.Substring(0, strResponse.IndexOf("&expires")); } AccessToken = strResponse.Replace("access_token=", ""); streamIn.Close(); } Facebook.FacebookAPI api = new Facebook.FacebookAPI(AccessToken); string request = "/me"; JSONObject fbobject = api.Get(request); try { ViewBag.FacebookID = fbobject.Dictionary["id"].String; ViewBag.FirstName = fbobject.Dictionary["first_name"].String; ViewBag.LastName = fbobject.Dictionary["last_name"].String; ViewBag.Email = fbobject.Dictionary["email"].String; //Here we can get all data using fbobject.Dictionary string str = string.Format("http://graph.facebook.com/{0}?fields=picture&type=normal", fbobject.Dictionary["id"].String); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(str); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); JObject je = new JObject(); je = JObject.Parse(strResponse); string pictureuser = je["picture"]["data"]["url"].ToString(); ViewBag.Photo = pictureuser; FormsAuthentication.SetAuthCookie(ViewBag.Email, true); } catch (Exception ex) { //errorLog.setError(ex, "LoginController.SaveFacebookData"); } } catch (Exception ex) { //errorLog.setError(ex, "LoginController.returnfromfb"); } return(RedirectToAction("Home", "Home")); }
private void GetFriendsbtn_Click(object sender, EventArgs e) { FacebookAPI api = new Facebook.FacebookAPI(myToken.Default.token); JSONObject me = api.Get("/me"); var yo = me.Dictionary["id"].String; //gets your user id myToken.Default.userId = yo.ToString();//save your id JSONObject friendsData = api.Get("/me/friends");//pulls all your friends //pulls your profile image pictureMyImage.Image = getUrlImage("https://graph.facebook.com/" + myToken.Default.userId + "/picture"); var data = friendsData.Dictionary["data"]; List<JSONObject> listofFriends = data.Array.ToList<JSONObject>(); //loop to grab any fields like friends ID, Name....... foreach (var friend in listofFriends) { myFriendsData.Add(friend.Dictionary["id"].String, friend.Dictionary["name"].String); myFriendsDataReverse.Add(friend.Dictionary["name"].String, friend.Dictionary["id"].String); friendsName.Items.Add(friend.Dictionary["name"].String);//adding each friends name to a listBox } //last get all my wall data myWall.Items.Clear(); getMyWallData(); }
private void ProcessFacebookData(string path, Func<JSONObject, List<Task>> task) { List<Task> tasks = new List<Task>(); var api = new FacebookAPI(Token); var args = new Dictionary<string, string>(); args.Add("limit", "100"); var results = api.Get(path, args); var next = (results.Dictionary.ContainsKey("paging")) && results.Dictionary["paging"].Dictionary.ContainsKey("next") ? results.Dictionary["paging"].Dictionary["next"].String : null; do { tasks.AddRange(task(results.Dictionary["data"])); if (!string.IsNullOrEmpty(next)) { args = new Dictionary<string, string>(); args.Add("until", next.Split(new string[] { "until=" }, StringSplitOptions.RemoveEmptyEntries)[1]); args.Add("limit", "100"); results = api.Get(path, args); if (results.Dictionary.ContainsKey("paging")) { if (next != results.Dictionary["paging"].Dictionary["next"].String) next = results.Dictionary["paging"].Dictionary["next"].String; else { next = null; results = null; } } else { next = null; results = null; } } else results = null; } while (results != null); Task.WaitAll(tasks.ToArray()); }
protected void LoadFacebookSearch(string name) { try { Panel1.Visible = true; List<FB_User> ListOfUsers = new List<FB_User>(); Sage.Platform.Application.Services.IUserOptionsService userOption = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Application.Services.IUserOptionsService>(); string token = userOption.GetCommonOption("AccessToken", "Facebook"); Facebook.FacebookAPI api = new Facebook.FacebookAPI(token); if (ddlSearchType.SelectedValue == "Public") { Dictionary<string, string> param = new Dictionary<string, string>(); param.Add("q", name.ToLower()); param.Add("type", "user"); if (!string.IsNullOrEmpty(ddlLimit.SelectedValue)) { param.Add("limit", ddlLimit.SelectedValue); } else { param.Add("limit", "100"); } if (!string.IsNullOrEmpty(ddlOffSet.SelectedValue)) { param.Add("offset", ddlOffSet.SelectedValue); } JSONObject result = api.Get("/search", param); if (result.Dictionary["data"].Array.Length > 0) { foreach (JSONObject j in result.Dictionary["data"].Array) { FB_User user = new FB_User(); user.Name = j.Dictionary["name"].String; user.Id = j.Dictionary["id"].String; user.ImageURL = String.Format("http://graph.facebook.com/{0}/picture", j.Dictionary["id"].String); ListOfUsers.Add(user); } } } else if (ddlSearchType.SelectedValue == "Friends") { JSONObject result = api.Get("/me/friends"); if (result.Dictionary["data"].Array.Length > 0) { foreach (JSONObject j in result.Dictionary["data"].Array) { if (j.Dictionary["name"].String.Contains(txtSearch.Text)) { FB_User user = new FB_User(); user.Name = j.Dictionary["name"].String; user.Id = j.Dictionary["id"].String; if (ddImgSize.SelectedValue == "Small") { user.ImageURL = String.Format("http://graph.facebook.com/{0}/picture", j.Dictionary["id"].String); } else { user.ImageURL = String.Format("http://graph.facebook.com/{0}/picture?type=large", j.Dictionary["id"].String); } ListOfUsers.Add(user); } } } } rptUserList.DataSource = ListOfUsers; rptUserList.DataBind(); } catch (Exception) { } }
// // POST: /Account/LoginWithFacebook public ActionResult ReturnFromFacebook() { string code = Request.QueryString["code"]; if (code == null) { return RedirectToAction("Home", "Home"); } string AccessToken = ""; try { if (code != null) { string str = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri=http://{1}/Account/ReturnFromFacebook&client_secret={2}&code={3}", System.Web.Configuration.WebConfigurationManager.AppSettings["facebookAppId"], Request.Url.Authority, System.Web.Configuration.WebConfigurationManager.AppSettings["facebookAppSecret"], code); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(str); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; byte[] Param = Request.BinaryRead(System.Web.HttpContext.Current.Request.ContentLength); string strRequest = System.Text.Encoding.ASCII.GetString(Param); req.ContentLength = strRequest.Length; StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); streamOut.Write(strRequest); streamOut.Close(); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); if (strResponse.Contains("&expires")) strResponse = strResponse.Substring(0, strResponse.IndexOf("&expires")); AccessToken = strResponse.Replace("access_token=", ""); streamIn.Close(); } Facebook.FacebookAPI api = new Facebook.FacebookAPI(AccessToken); string request = "/me"; JSONObject fbobject = api.Get(request); try { ViewBag.FacebookID = fbobject.Dictionary["id"].String; ViewBag.FirstName = fbobject.Dictionary["first_name"].String; ViewBag.LastName = fbobject.Dictionary["last_name"].String; ViewBag.Email = fbobject.Dictionary["email"].String; //Here we can get all data using fbobject.Dictionary string str = string.Format("http://graph.facebook.com/{0}?fields=picture&type=normal", fbobject.Dictionary["id"].String); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(str); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); JObject je = new JObject(); je = JObject.Parse(strResponse); string pictureuser = je["picture"]["data"]["url"].ToString(); ViewBag.Photo = pictureuser; FormsAuthentication.SetAuthCookie(ViewBag.Email, true); } catch (Exception ex) { //errorLog.setError(ex, "LoginController.SaveFacebookData"); } } catch (Exception ex) { //errorLog.setError(ex, "LoginController.returnfromfb"); } return RedirectToAction("Home", "Home"); }
public ActionResult returnfromfb() { Employee e = new Employee(); string code = Request.QueryString["code"]; if (code == null) { return(RedirectToAction("LastWindow", "Login")); } string AccessToken = ""; try { if (code != null) { string str = "https://graph.facebook.com/oauth/access_token?client_id=" + System.Web.Configuration.WebConfigurationManager.AppSettings["facebookappid"] + "&redirect_uri=http://" + Request.Url.Authority + "/Home/returnfromfb&client_secret=" + System.Web.Configuration.WebConfigurationManager.AppSettings["facebookappsecret"] + "&code=" + code; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(str); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; byte[] Param = Request.BinaryRead(System.Web.HttpContext.Current.Request.ContentLength); string strRequest = System.Text.Encoding.ASCII.GetString(Param); req.ContentLength = strRequest.Length; StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); streamOut.Write(strRequest); streamOut.Close(); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); if (strResponse.Contains("&expires")) { strResponse = strResponse.Substring(0, strResponse.IndexOf("&expires")); } AccessToken = strResponse.Replace("access_token=", ""); streamIn.Close(); } Facebook.FacebookAPI api = new Facebook.FacebookAPI(AccessToken); string request = "/me"; Facebook.JSONObject fbobject = api.Get(request); try { string fbId = fbobject.Dictionary["id"].String; string email = fbobject.Dictionary["email"].String; Employee e2 = db.EmployeeDB.Where(x => x.Email == email).FirstOrDefault(); if (e2 == null) { Employee e1 = db.EmployeeDB.Where(x => x.FacebookId == fbId).FirstOrDefault(); if (e1 == null) { e.FirstName = fbobject.Dictionary["first_name"].String; e.LastName = fbobject.Dictionary["last_name"].String; e.Email = email; e.Gender = fbobject.Dictionary["gender"].String; if (fbobject.Dictionary.ContainsKey("birthday")) { e.DateOfBirth = Convert.ToDateTime(fbobject.Dictionary["birthday"].String); } e.FacebookId = fbId; e.Created = DateTime.Now; e.Updated = DateTime.Now; db.EmployeeDB.Add(e); db.SaveChanges(); Session["userId"] = e.Id; Session["firstLogin"] = true; string str = "http://graph.facebook.com/" + fbobject.Dictionary["id"].String + "?fields=picture.type(large)"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(str); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); JObject je = new JObject(); je = JObject.Parse(strResponse); string ProfilePicURL = je["picture"]["data"]["url"].ToString().Replace("\"", ""); UploadProfilePic(ProfilePicURL, e.Id); } else { return(RedirectToAction("Resume", "Profile")); } } else { e2.FacebookId = fbId; db.SaveChanges(); Session["userId"] = e2.Id; return(RedirectToAction("Resume", "Profile")); } } catch (Exception ex) { } } catch (Exception ex) { } return(RedirectToAction("Resume", "Profile")); }
public ActionResult returnfromfb() { string code = Request.QueryString["code"]; if (code == null) { return RedirectToAction("LastWindow", "Login"); } string AccessToken = ""; try { if (code != null) { string str = "https://graph.facebook.com/oauth/access_token?client_id=" + System.Web.Configuration.WebConfigurationManager.AppSettings["facebookappid"] + "&redirect_uri=http://" + Request.Url.Authority + "/login/returnfromfb&client_secret=" + System.Web.Configuration.WebConfigurationManager.AppSettings["facebookappsecret"] + "&code=" + code; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(str); req.Method = "POST"; req.ContentType = "application/x-www-form-urlencoded"; byte[] Param = Request.BinaryRead(System.Web.HttpContext.Current.Request.ContentLength); string strRequest = System.Text.Encoding.ASCII.GetString(Param); req.ContentLength = strRequest.Length; StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII); streamOut.Write(strRequest); streamOut.Close(); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); if (strResponse.Contains("&expires")) strResponse = strResponse.Substring(0, strResponse.IndexOf("&expires")); AccessToken = strResponse.Replace("access_token=", ""); streamIn.Close(); } Facebook.FacebookAPI api = new Facebook.FacebookAPI(AccessToken); string request = "/me"; JSONObject fbobject = api.Get(request); try { ViewBag.FacebookID = fbobject.Dictionary["id"].String; ViewBag.FirstName = fbobject.Dictionary["first_name"].String; ViewBag.LastName = fbobject.Dictionary["last_name"].String; ViewBag.Email = fbobject.Dictionary["email"].String; //You can get all data using fbobject.Dictionary string str = "http://graph.facebook.com/" + fbobject.Dictionary["id"].String + "?fields=picture&type=normal"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(str); StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()); string strResponse = streamIn.ReadToEnd(); JObject je = new JObject(); je = JObject.Parse(strResponse); string ProfilePicURL = je["picture"].ToString().Replace("\"", ""); } catch (Exception ex) { //errorLog.setError(ex, "LoginController.SaveFacebookData"); } } catch (Exception ex) { //errorLog.setError(ex, "LoginController.returnfromfb"); } return View(); }
protected string Process(string id) { try { IContact newContact = Sage.Platform.EntityFactory.Create<IContact>(); IAccount newAccount = Sage.Platform.EntityFactory.Create<IAccount>(); Sage.Platform.Application.Services.IUserOptionsService userOption = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Application.Services.IUserOptionsService>(); string token = userOption.GetCommonOption("AccessToken", "Facebook"); Facebook.FacebookAPI api = new Facebook.FacebookAPI(token); Facebook.JSONObject result = api.Get(id); newContact.FacebookId = id; if (result.Dictionary.ContainsKey("name")) { newContact.FirstName = result.Dictionary["first_name"].String; } if (result.Dictionary.ContainsKey("name")) { newContact.LastName = result.Dictionary["last_name"].String; } if (result.Dictionary.ContainsKey("birthday")) { newContact.Birthday = Convert.ToDateTime(result.Dictionary["birthday"].String); } if (result.Dictionary.ContainsKey("work")) { Facebook.JSONObject work = (Facebook.JSONObject)result.Dictionary["work"].Array.GetValue(0); string compId = work.Dictionary["employer"].Dictionary["id"].String; Facebook.JSONObject employer = api.Get(compId); newAccount.AccountName = employer.Dictionary["name"].String; newContact.AccountName = employer.Dictionary["name"].String; //txtOrg.Text = employer.Dictionary["category"].String; //lblCompDesc.Text = employer.Dictionary["description"].String; newAccount.WebAddress = employer.Dictionary["link"].String; } else { newAccount.AccountName = result.Dictionary["last_name"].String + "," + result.Dictionary["first_name"].String; newContact.AccountName = result.Dictionary["last_name"].String + "," + result.Dictionary["first_name"].String; } newAccount.Save(); newContact.Account = newAccount; newContact.Save(); string temp = string.Empty; temp = newContact.Id.ToString(); return temp; } catch (Exception) { return null; } }
protected void LoadFacebookSearch(string name) { try { Sage.Platform.Application.Services.IUserOptionsService userOption = Sage.Platform.Application.ApplicationContext.Current.Services.Get<Sage.Platform.Application.Services.IUserOptionsService>(); string token = userOption.GetCommonOption("AccessToken", "Facebook"); Facebook.FacebookAPI api = new Facebook.FacebookAPI(token); JSONObject result = api.Get("/me/friends"); JSONObject data = result.Dictionary["data"]; List<FB_User> friendsList = new List<FB_User>(); if (result.Dictionary["data"].Array.Length > 0) { foreach (JSONObject j in result.Dictionary["data"].Array) { if (j.Dictionary["name"].String.Contains(txtSearch.Text)) { FB_User user = new FB_User(); user.Name = j.Dictionary["name"].String; user.Id = j.Dictionary["id"].String; user.ImageURL = String.Format("http://graph.facebook.com/{0}/picture", j.Dictionary["id"].String); friendsList.Add(user); } } } GridView1.DataSource = friendsList; GridView1.DataBind(); } catch (Exception) { } }