public FacebookStreamMonitor(string accessToken, int pollInterval) { AccessToken = accessToken; PollInterval = pollInterval; m_facebook = new FacebookAPI(accessToken); }
public MainView() { InitializeComponent(); myFriendsData = new Dictionary<string, string>(); myFriendsDataReverse = new Dictionary<string, string>(); apiService = new FacebookAPI(); }
/// <summary> /// Makes a Facebook Graph API Call. /// </summary> /// <param name="relativePath">The path for the call, /// e.g. /username</param> /// <param name="httpVerb">The HTTP verb to use, e.g. /// GET, POST, DELETE</param> /// <param name="args">A dictionary of key/value pairs that /// will get passed as query arguments.</param> private JSONObject Call(string relativePath, HttpVerb httpVerb, Dictionary <string, string> args) { string remoteUri = FacebookAPI.DetermineBaseUri(relativePath); Uri baseURL = new Uri(remoteUri); Uri url = new Uri(baseURL, relativePath); if (args == null) { args = new Dictionary <string, string>(); } if (!string.IsNullOrEmpty(AccessToken)) { args["access_token"] = AccessToken; } JSONObject obj = JSONObject.CreateFromString(MakeRequest(url, httpVerb, args)); if (obj.IsDictionary && obj.Dictionary.ContainsKey("error")) { throw new FacebookAPIException(obj.Dictionary["error"] .Dictionary["type"] .String, obj.Dictionary["error"] .Dictionary["message"] .String); } return(obj); }
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!"; }
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; lblName.Text = "Hello " + facebookName; } }
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) { } }
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); var parameters = new Dictionary { { "message", 'Wow, I love Google!' }, { "name", 'Google' }, { "description", 'Description of post' }, { "picture", 'http://www.google.com/logo.png' }, { "caption", 'This is google.com' }, { "link", 'http://www.google.com' }, { "type", "link" } }; JSONObject wallPost = api.MakeRequest("/[PAGE_ID]/feed", 'POST', parameters); } } }
private void frndPostBtn_Click(object sender, EventArgs e) { try { //same thing pass your app token FacebookAPI api = new FacebookAPI(myToken.Default.token); //build a dictionary Dictionary<string, string> postArgs = new Dictionary<string, string>(); postArgs["message"] = txtFrndPost.Text;//key message, value text //send to fb JSONObject post = api.Post("/ " + frndIDBoxMsg.Text + "/feed", postArgs); //clear friend wall //refresh data getSentMessage(); //clear text box txtFrndPost.Text = ""; } catch (FacebookAPIException exr) { Console.WriteLine(exr.Message); } }
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) { } }
ReloginMethod ( ) { FacebookLoginDialog o_fcbLoginDialog = new FacebookLoginDialog(new FacebookGraphDataProviderDialogBase(), UserAttributes.createRequiredPermissionsString(bGetStatusUpdates, bGetWallPosts,false)); o_fcbLoginDialog.LogIn(); fbAPI = new FacebookAPI(o_fcbLoginDialog.LocalAccessToken); }
// // 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"); }
GetFanPageNetworkInternal ( string sAccessToken, string fanPageUsernameID, List<NetworkType> netTypes, int iFromPost, int iToPost, Dictionary<Attribute,bool> attributes, bool getStatusUpdates, bool getWallPosts, bool includeOthers, DateTime startDate, DateTime endDate, int iLimit ) { JSONObject streamPosts; Dictionary<string, Dictionary<string, List<string>>> commentersComments = new Dictionary<string,Dictionary<string,List<string>>>(); Dictionary<string, List<string>> likersPosts=new Dictionary<string,List<string>>(); usersDisplayName = new Dictionary<string,string>(); fbAPI = new FacebookAPI(sAccessToken); bGetStatusUpdates = getStatusUpdates; bGetWallPosts = getWallPosts; if (bGetStatusUpdates) NrOfSteps++; if (bGetWallPosts) NrOfSteps++; RequestStatistics oRequestStatistics = new RequestStatistics(); //Download data streamPosts = DownloadPosts(fanPageUsernameID, iFromPost, iToPost, includeOthers, startDate, endDate); if (netTypes.Contains(NetworkType.UserUserComments) || netTypes.Contains(NetworkType.UserPostComments) || netTypes.Contains(NetworkType.PostPostComments)) { commentersComments = DownloadComments(streamPosts, iLimit); } if (netTypes.Contains(NetworkType.UserUserLikes) || netTypes.Contains(NetworkType.UserPostLikes) || netTypes.Contains(NetworkType.PostPostLikes)) { likersPosts = DownloadLikes(streamPosts, iLimit); } //Create the network GraphMLXmlDocument oGraphMLXmlDocument = CreateGraphMLXmlDocument(attributes, netTypes); Dictionary<string, Dictionary<string, JSONObject>> attributeValues = new Dictionary<string, Dictionary<string, JSONObject>>(); AddVertices(ref oGraphMLXmlDocument, ref attributeValues, attributes, netTypes, commentersComments, likersPosts, streamPosts); AddEdges(ref oGraphMLXmlDocument, netTypes, commentersComments, likersPosts, streamPosts, attributeValues); OnNetworkObtainedWithoutTerminatingException(oGraphMLXmlDocument, oRequestStatistics, GetNetworkDescription(streamPosts, fanPageUsernameID, netTypes, iFromPost, iToPost, startDate, endDate, oGraphMLXmlDocument)); return oGraphMLXmlDocument; }
//private string GetPostAuthorForLikerCommenter(JSONObject oLikerCommenter) //{ // JSONObject oFirstResult = null; // foreach (KeyValuePair<string, List<JSONObject>> kvp in oPosts) // { // oFirstResult = kvp.Value.FirstOrDefault(x => x.Dictionary["post_id"].String == oLikerCommenter.Dictionary["post_id"].String); // if (oFirstResult!=null) // { // return oFirstResult.Dictionary["actor_id"].String; // } // } // return null; //} private List<JSONObject> FQLBatchRequest(FacebookAPI fb, List<string> oQueries) { Dictionary<string, string> oBatchArguments = new Dictionary<string, string>(); string oBatch; int nrOfQueries = oQueries.Count; int nrOfCalls = (int)Math.Ceiling((double)nrOfQueries / 49); int startIndex, endIndex; List<JSONObject> results = new List<JSONObject>(); for (int i = 0; i < nrOfCalls; i++) { ReportProgress(String.Format( "Step {0}/{1}: Downloading Friends of Friends data (batch {2}/{3})", CurrentStep, NrOfSteps, i+1, nrOfCalls)); startIndex = i * 49; endIndex = nrOfQueries - startIndex <= 49 ? nrOfQueries - startIndex : 49; oBatch = String.Empty; oBatch += "["; foreach (string oQuery in oQueries.Skip(startIndex).Take(endIndex)) { oBatch += "{\"method\":\"POST\",\"relative_url\":\"method/fql.query?query=" + oQuery + "\",},"; } oBatch += "]"; oBatchArguments.Clear(); oBatchArguments.Add("batch", oBatch); results.Add(fb.Post("", oBatchArguments)); } return results; }
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")); }
private JSONObject[] SearchMyGroups(string sGroupName) { s_accessToken = o_fcbLoginDialog.LocalAccessToken; if (fb == null) { if (String.IsNullOrEmpty(s_accessToken)) { fb = new FacebookAPI(); } else { fb = new FacebookAPI(s_accessToken); } } Dictionary<string, string> args = new Dictionary<string, string>(); args.Add("fields", "icon,name"); JSONObject[] result = fb.Get("me/groups", args).Dictionary["data"].Array.Where(x => x.Dictionary["name"].String.IndexOf(sGroupName,StringComparison.OrdinalIgnoreCase)>=0).ToArray(); return result; }
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) { } }
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; } }
GetFriendsNetworkInternal ( string sAccessToken, List<NetworkType> oEdgeType, bool bDownloadFromPostToPost, bool bDownloadBetweenDates, bool bEgoTimeline, bool bFriendsTimeline, int iFromPost, int iToPost, DateTime oStartDate, DateTime oEndDate, bool bLimitCommentsLikes, int iNrLimit, bool bGetTooltips, bool bIncludeMe, AttributesDictionary<bool> attributes ) { Debug.Assert(!String.IsNullOrEmpty(sAccessToken)); AssertValid(); //Set the total nr of steps if (bGetTooltips) NrOfSteps++; oTimer.Elapsed += new System.Timers.ElapsedEventHandler(oTimer_Elapsed); oGraphMLXmlDocument = CreateGraphMLXmlDocument(attributes); RequestStatistics oRequestStatistics = new RequestStatistics(); var fb = new FacebookAPI(sAccessToken); m_oFb = fb; Dictionary<string, string> friends = new Dictionary<string, string>(); List<string> friendsUIDs = new List<string>(); XmlNode oVertexXmlNode; string attributeValue = ""; Dictionary<String, List<Dictionary<string, object>>> statusUpdates = new Dictionary<string, List<Dictionary<string, object>>>(); Dictionary<String, List<Dictionary<string, object>>> wallPosts = new Dictionary<string,List<Dictionary<string,object>>>(); string currentStatusUpdate=""; string currentWallPost = ""; string currentWallTags = ""; string currentStatusTags = ""; List<Dictionary<string,object>>.Enumerator en; bool bGetUsersTagged = oEdgeType.Contains(NetworkType.TimelineUserTagged); bool bGetCommenters = oEdgeType.Contains(NetworkType.TimelineUserComments); bool bGetLikers = oEdgeType.Contains(NetworkType.TimelineUserLikes); bool bGetPostAuthors = oEdgeType.Contains(NetworkType.TimelinePostAuthors); bool bGetPosts = oEdgeType.Count > 0; DownloadFriends(); if (bEgoTimeline || bIncludeMe) { GetEgo(); } oVerticesToQuery = VerticesToQuery(bEgoTimeline, bFriendsTimeline); if (bGetPosts) { DownloadPosts(bDownloadFromPostToPost, bDownloadBetweenDates, iFromPost, iToPost, oStartDate, oEndDate, bGetUsersTagged , bGetCommenters, bGetLikers); } DownloadVertices(bGetUsersTagged, bGetCommenters, bGetLikers, bGetPosts, bLimitCommentsLikes, iNrLimit); DownloadAttributes(attributes); if(bGetTooltips) { GetTooltips(); } CreateEdges(bGetUsersTagged, bGetCommenters, bGetLikers, bGetPostAuthors, bIncludeMe); AddVertices(); ReportProgress(String.Format("Completed downloading {0} friends data", friends.Count)); AddEdges(); ReportProgress("Importing downloaded network into NodeXL"); //After successfull download of the network //get the network description OnNetworkObtainedWithoutTerminatingException(oGraphMLXmlDocument, oRequestStatistics, GetNetworkDescription(oEdgeType, bDownloadFromPostToPost, bDownloadBetweenDates, iFromPost, iToPost, oStartDate, oEndDate, bLimitCommentsLikes, iNrLimit, oGraphMLXmlDocument)); return oGraphMLXmlDocument; }
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(); }
public Facebook(string token) { api = new FacebookAPI(token); }
private void StatusUpdate_Click(object sender, EventArgs e) { try { //same thing pass your app token FacebookAPI api = new FacebookAPI(myToken.Default.token); //build a dictionary Dictionary<string, string> postArgs = new Dictionary<string, string>(); postArgs["message"] = txtPost.Text;//key message, value text //postArgs["picture"] = "http://test.com/folder/test-image.jpg";//pass a image url //send to fb JSONObject post = api.Post("/ " + myToken.Default.userId + "/feed", postArgs); //clear wall myWall.Items.Clear(); //refresh data getMyWallData(); //clear text box txtPost.Text = ""; } catch (FacebookAPIException exr) { Console.WriteLine(exr.Message); } }
/// <summary> /// Determnie the correct base URI for FB API requests. /// </summary> /// <param name="relativePath">Relative path for request</param> /// <returns>Correct base uri for the given path</returns> private static string DetermineBaseUri(string relativePath) { return(FacebookAPI.IsLegacyRESTPath(relativePath) ? FacebookAPI.LegacyRESTUri : FacebookAPI.GraphUri); }
// // 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() { 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(); }
private JSONObject Search(string sPageName) { if (fb == null) { if (String.IsNullOrEmpty(s_accessToken)) { s_accessToken = o_fcbLoginDialog.LocalAccessToken; fb = new FacebookAPI(); } else { fb = new FacebookAPI(s_accessToken); } } Dictionary<string, string> args = new Dictionary<string, string>(); args.Add("fields", "picture,name,category,likes,talking_about_count"); args.Add("q", sPageName); args.Add("type", "page"); args.Add("limit", "15"); args.Add("access_token", s_accessToken); JSONObject result = fb.Get("search", args); bgLoadResults.ReportProgress(100, result); return result; }
private JSONObject[] SearchPublic(string sGroupName) { JSONObject result; if (fb == null) { if (String.IsNullOrEmpty(s_accessToken)) { fb = new FacebookAPI(); } else { fb = new FacebookAPI(s_accessToken); } } Dictionary<string, string> args = new Dictionary<string, string>(); args.Add("fields", "icon,name"); args.Add("q", sGroupName); args.Add("type", "group"); args.Add("limit", "15"); result = fb.Get("search", args); return result.Dictionary["data"].Array; }