Exemple #1
0
        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();
            }
        }
Exemple #2
0
        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;
            }
        }