-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrowser.cs
More file actions
105 lines (86 loc) · 3.15 KB
/
Copy pathBrowser.cs
File metadata and controls
105 lines (86 loc) · 3.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.Windows.Forms;
using System.Text.RegularExpressions;
namespace FB_API_Plugin
{
internal partial class Browser : Form
{
public Browser()
{
InitializeComponent();
}
//ool nav = false;
public string Url { get; set; }
public string RedirectUrl { get; set; }
public new void ShowDialog()
{
throw new NotImplementedException();
}
public string GetToken { get; set; }
private void Browser_Load(object sender, EventArgs e)
{
webBrowser1.Navigate(Url);
//WaitForPageLoad();
//nav = true;
}
private bool Pageready { get; set; }
//#region "Page Loading Functions"
//public void WaitForPageLoad()
//{
// webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(PageWaiter);
// while (!pageready)
// {
// Application.DoEvents();
// }
// pageready = false;
//}
//private void PageWaiter(object sender, WebBrowserDocumentCompletedEventArgs e)
//{
// if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
// {
// pageready = true;
// string url = webBrowser1.Url.ToString();
// string host = new Uri(RedirectUrl).Host;
// if (url.Contains(host))
// {
// Match mt = Regex.Match(url, "(?<=#access_token=).*(?=&expires_in)");
// if (mt.Success)
// {
// this.GetToken = mt.Groups[0].Value;
// this.DialogResult = System.Windows.Forms.DialogResult.OK;
// }
// }
// // webBrowser1.DocumentCompleted -= new WebBrowserDocumentCompletedEventHandler(PageWaiter);
// }
//}
//#endregion
private void webBrowser1_Navigated(object sender, WebBrowserNavigatedEventArgs e)
{
//if (nav == true)
//{
// WaitForPageLoad();
//}
}
private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
//WaitForPageLoad();
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
var url = webBrowser1.Url.ToString();
var host = new Uri(RedirectUrl).Host;
if (url.Contains(host))
{
var mt = Regex.Match(url, "(?<=#access_token=).*(?=&expires_in)");
if (!mt.Success) return;
GetToken = mt.Groups[0].Value;
DialogResult = DialogResult.OK;
}
else if (url.Contains("developers.facebook.com/tools/explorer/callback"))
{
GetToken = "";
DialogResult = DialogResult.OK;
}
}
}
}