private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e) { if (webBrowser1.Url.AbsoluteUri.Contains("access_token")) { //authentcation is successfull string url1 = webBrowser1.Url.AbsoluteUri; string url2 = url1.Substring(url1.IndexOf("access_token", StringComparison.Ordinal) + 13); string token = url2.Substring(0, url2.IndexOf("&", StringComparison.Ordinal)); AccessToken = token; //save to database FacebookApiEntities db = new FacebookApiEntities(); FacebookClient fbclient = new FacebookClient(token); dynamic account = fbclient.Get("/me?fields=email,name"); AccountTbl acc = db.AccountTbls.Find(account.id); if (acc != null) { acc.AccEmail = account.email; acc.AccName = account.name; acc.AccToken = token; } else { AccountTbl NewAcc = new AccountTbl(); NewAcc.AccEmail = account.email; NewAcc.AccName = account.name; NewAcc.AccToken = token; NewAcc.AccID = account.id; db.AccountTbls.Add(NewAcc); } db.SaveChanges(); } }
private void button1_Click(object sender, EventArgs e) { FacebookApiEntities fb = new FacebookApiEntities(); AccountTbl acc = fb.AccountTbls.Find(cBxAccounts.SelectedValue.ToString()); SelectedAccID = acc.AccID; textToken.Text = acc.AccToken; SelectedToken = acc.AccToken; textAccountName.Text = acc.AccName; //validate try { FacebookClient FbCLient = new FacebookClient(SelectedToken); dynamic testacc = FbCLient.Get("/me"); lblStat.Text = "Success"; lblStat.ForeColor = Color.Green; } catch { lblStat.Text = "Invalid"; lblStat.ForeColor = Color.Red; } }
private void Form1_Load(object sender, EventArgs e) { //bind the combo box to accounts table FacebookApiEntities fb = new FacebookApiEntities(); cBxAccounts.DataSource = fb.AccountTbls.ToList(); cBxAccounts.DisplayMember = "AccEmail"; cBxAccounts.ValueMember = "AccID"; cBxAccounts.Invalidate(); }
private void BtnUpdateManagedPages_Click(object sender, EventArgs e) { FacebookApiEntities db = new FacebookApiEntities(); FacebookClient fbclient = new FacebookClient(SelectedToken); dynamic Mypages = fbclient.Get("/me/accounts?fields=access_token,name,id,fan_count&limit=1000"); int counter = Convert.ToInt32(Mypages.data.Count); //save to database for (var i = 0; i < counter; i++) { PagesTbl pg = db.PagesTbls.Find(Mypages.data[i].id); if (pg != null) { //page already exists then update pg.PageName = Mypages.data[i].name; pg.PageToken = Mypages.data[i].access_token; pg.fans = Mypages.data[i].fan_count; } else { //create a record for the page PagesTbl Newpage = new PagesTbl(); Newpage.PageName = Mypages.data[i].name; Newpage.PageToken = Mypages.data[i].access_token; Newpage.fans = Mypages.data[i].fan_count; Newpage.PageID = Mypages.data[i].id; Newpage.ParentAccountID = SelectedAccID; db.PagesTbls.Add(Newpage); } db.SaveChanges(); //load to our listview listViewManagedPages.Items.Clear(); foreach (PagesTbl page in db.PagesTbls.ToList()) { ListViewItem lsitem = new ListViewItem(); lsitem.Text = page.PageName; lsitem.SubItems.Add(page.fans.ToString()); lsitem.SubItems.Add(page.PageID); lsitem.SubItems.Add(page.PageToken); listViewManagedPages.Items.Add(lsitem); } } }
private void BtnLogin_Click(object sender, EventArgs e) { LoginFrm NewLogin = new LoginFrm(); NewLogin.ShowDialog(); if (NewLogin.AccessToken != null) { //sucecss FacebookApiEntities fb = new FacebookApiEntities(); cBxAccounts.DataSource = fb.AccountTbls.ToList(); cBxAccounts.DisplayMember = "AccEmail"; cBxAccounts.ValueMember = "AccID"; cBxAccounts.Invalidate(); } }
private void BtnGetManagedPages_Click(object sender, EventArgs e) { //load to our listview FacebookApiEntities db = new FacebookApiEntities(); listViewManagedPages.Items.Clear(); foreach (PagesTbl page in db.PagesTbls.ToList()) { ListViewItem lsitem = new ListViewItem(); lsitem.Text = page.PageName; lsitem.SubItems.Add(page.fans.ToString()); lsitem.SubItems.Add(page.PageID); lsitem.SubItems.Add(page.PageToken); listViewManagedPages.Items.Add(lsitem); } }