Anonymous Anonymous - 1 year ago
724 0

No description

VB Twitter API Example

<?xml version="1.0" encoding="utf-8" ?>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    <!-- Fill in your consumer key and secret here to make the OAuth sample work. -->
    <!-- Twitter sign-up: -->
    <add key="twitterConsumerKey" value="5eksjF9yEXMmb545DNmK23o2v"/>
    <add key="twitterConsumerSecret" value="mrtfUgvRW4hTUKXeue5LET7bTD7sn2puxXzJYDEHUDq7HdOAm1"/>
    <add key="twitterOAuthToken" value="720689202388680704-p6FJ5nPjY541bRQ1jgxbdBKpBmPErGK"/>
    <add key="twitterAccessToken" value="gkEI6O5U6Hgw2UAsVqmTvvue1ePj2DSrL51nFypX3QdkR"/>

VB Code
Imports LinqToTwitter
Imports System.Configuration

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    End Sub

    Sub Main()
        ' get user credentials and instantiate TwitterContext

        If String.IsNullOrEmpty(ConfigurationManager.AppSettings("twitterConsumerKey")) Or String.IsNullOrEmpty(ConfigurationManager.AppSettings("twitterConsumerSecret")) Then
            Console.WriteLine("Please set the Twitter consumer key and secret values in the app.config file and run again.")
            Exit Sub
        End If

        Dim credentials As New XAuthCredentials

        credentials.ConsumerKey = ConfigurationManager.AppSettings("twitterConsumerKey")
        credentials.ConsumerSecret = ConfigurationManager.AppSettings("twitterConsumerSecret")

        Dim auth As PinAuthorizer = New PinAuthorizer()
        auth.CredentialStore = credentials
        auth.GetPin = AddressOf VerifierCallback
        auth.GoToTwitterAuthorization = Function(pageLink) Process.Start(pageLink)

        Dim twitterCtx As TwitterContext = New TwitterContext(auth)

        twitterCtx.Log = Console.Out


        Dim twitterContext = New TwitterContext(auth)


    End Sub

    Private Function VerifierCallback() As String
        Console.WriteLine("Next, you'll need to tell Twitter to authorize access.\nThis program will not have access to your credentials, which is the benefit of OAuth.\nOnce you log into Twitter and give this program permission,\n come back to this console.")
        Console.Write("Please enter the PIN that Twitter gives you after authorizing this client: ")
        Return Console.ReadLine()
    End Function

    Private Sub UserStatusByNameDemo(ByVal twitterCtx As TwitterContext)
        Dim lastN As Integer = 20
        Dim screenName As String = "reecepeel_"

        Dim ts = From t In twitterCtx.Status
                 Where t.Type = StatusType.User _
                 And t.ScreenName = screenName _
                 And t.Count = lastN

        For Each tweet In ts
            txtTweets.Text = (
                "(" & tweet.ID & ")" &
                "[" & tweet.User.UserID & "]" &
                tweet.User.Name & ", " &
                tweet.Text & ", " &
    End Sub

End Class
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download