Imports System.Net 'Details see: 'http://frank-it-beratung.com/2011/10/11/facebook-access-tokens-mit-fb-access-token-manager-erstellen-neue-version-mit-kleinen-verbesserungen/ Public Class frmMain Private Sub cmdGetToken_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdGetToken.Click If txtClientID.Text = "" Then MsgBox("client_id needed!") Exit Sub End If cmdGetToken.Enabled = False webMeinBrowser.Navigate(txtURL.Text) End Sub Private Sub txtClientID_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtClientID.TextChanged BaueURL() End Sub Private Sub BaueURL() Dim u As String = "https://graph.facebook.com/oauth/authorize?" Dim s As String = "" If chkScope1.Checked Then s = s + chkScope1.Text + "," End If If chkScope2.Checked Then s = s + chkScope2.Text + "," End If If chkScope3.Checked Then s = s + chkScope3.Text + "," End If If chkScope4.Checked Then s = s + chkScope4.Text + "," End If If chkScope5.Checked Then s = s + chkScope5.Text + "," End If If txtScope.Text <> "" Then s = s + txtScope.Text End If s = s.Trim(",") u = u + "client_id=" + txtClientID.Text u = u + "&scope=" + s u = u + "&redirect_uri=http://www.facebook.com/connect/login_success.html" u = u + "&type=user_agent" u = u + "&display=popup" txtURL.Text = u End Sub Private Sub chkScope_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkScope1.CheckedChanged, chkScope2.CheckedChanged, chkScope3.CheckedChanged, chkScope4.CheckedChanged, chkScope5.CheckedChanged BaueURL() End Sub Private Sub txtScope_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtScope.TextChanged BaueURL() End Sub Private Sub webMeinBrowser_Navigated(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatedEventArgs) Handles webMeinBrowser.Navigated Dim q As String = webMeinBrowser.Url.ToString() If q.Contains("#access_token=") Then q = q.Substring(q.IndexOf("access_token=") + 13) txtAToken.Text = q.Substring(0, q.IndexOf("&")) End If cmdGetToken.Enabled = True End Sub Private Sub cmdPageAccessToken_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPageAccessToken.Click Dim u As String = "https://graph.facebook.com/me/accounts/?access_token=" + txtAToken.Text Dim Antwort As Byte() Dim AntwortJson As String Dim myWebClient As New WebClient() If txtAToken.Text = "" Then MsgBox("Not possible - Get or type Access-Token with manage_page Scope first!") Exit Sub End If cmdPageAccessToken.Enabled = False Try Antwort = myWebClient.DownloadData(u) AntwortJson = System.Text.Encoding.ASCII.GetString(Antwort) ' Ausgabe ein wenig schöner gestalten ... AntwortJson = AntwortJson.Replace(",", "," & vbLf) AntwortJson = AntwortJson.Replace("{", vbLf & "{") webMeinBrowser.DocumentText = "
" & AntwortJson & "
" Catch ex As Exception webMeinBrowser.DocumentText = "
" & ex.Message.ToString & "
" End Try cmdPageAccessToken.Enabled = True End Sub Private Sub lblLink_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles lblLink.LinkClicked Process.Start("http://frank-it-beratung.com/2010/12/05/facebook-access-token-tool/") End Sub Private Sub cmdZuFacebook_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdZuFacebook.Click webMeinBrowser.Navigate("http://www.facebook.com") End Sub Private Sub cmdTesteToken_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdTesteToken.Click Dim u As String = "https://graph.facebook.com/me/?access_token=" + txtAToken.Text Dim Antwort As Byte() Dim AntwortJson As String Dim myWebClient As New WebClient() If txtAToken.Text = "" Then MsgBox("Not possible - Get or type Access-Token first!") Exit Sub End If Try Antwort = myWebClient.DownloadData(u) AntwortJson = System.Text.Encoding.ASCII.GetString(Antwort) ' Ausgabe ein wenig schöner gestalten ... AntwortJson = AntwortJson.Replace(",", "," & vbLf) AntwortJson = AntwortJson.Replace("{", vbLf & "{") webMeinBrowser.DocumentText = "
" & AntwortJson & "
" Catch ex As Exception webMeinBrowser.DocumentText = "
" & ex.Message.ToString & "
" End Try End Sub Private Sub frmMain_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed Process.Start("http://frank-it-beratung.com/etc/danke/") End Sub End Class