Problem with VBNET & Linq2Twitter - SingleUserAuthorizer

Oct 21, 2013 at 5:48 AM
First of all, thx for your help

I can't Connect with Twitter... And alway I have the same problem 401 - Could not autentificate you

This is my code:
Public twitterCtx As TwitterContext
Private Sub Start_TWT()
Dim Credentials As SingleUserInMemoryCredentials = New SingleUserInMemoryCredentials

        'Credentials.ConsumerKey = ConfigurationManager.AppSettings("twitterConsumerKey")
        Credentials.ConsumerKey = "Cixxxxxxx"
        Credentials.ConsumerSecret = "RMQRPLqhmhxxxxxxxxdQ"
        Credentials.OAuthToken = "219441688-KKaKmJNuHxxxxxxxxxhDDrj2G48jK"
        Credentials.AccessToken = "WcaBrxxxxxxxxxxxxxxxxxxxxxxxxxxUwBDI"

        Dim auth As SingleUserAuthorizer = New SingleUserAuthorizer

            auth.Credentials = Credentials

            twitterCtx = New TwitterContext(auth)

SearchTwitterDemo(twitterCtx)

End Sub

Private Sub SearchTwitterDemo(ByVal twitterCtx As TwitterContext)
        Try

        
        Dim queryResults = _
            From search In twitterCtx.Search _
            Where search.Type = SearchType.Search _
            And search.Query = TextBox1.Text

        'RichTextBox1.AppendText("Query: " & Environment.NewLine)

        For Each searchResult In queryResults
            For Each entry In searchResult.Statuses
                RichTextBox1.AppendText("ID: {0}, Source: {1} - Content: {2}" & Environment.NewLine & entry.ID & Environment.NewLine & entry.Source & Environment.NewLine & entry.Text)
            Next
            Next
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try
    End Sub
Thnx
Coordinator
Oct 21, 2013 at 6:07 AM
Hi,

There are many things that will cause a 401. I've written a LINQ to Twitter FAQ that has several suggestions and items to check.

@JoeMayo
Oct 21, 2013 at 1:53 PM
Hi...

I solved some problems but others have appeared...
 Public AUTH As SingleUserAuthorizer
    Public TWITTERCTX As TwitterContext

    Sub Arrancar_TWITTER()
        '
        ' get user credentials and instantiate TwitterContext
    
        AUTH = New SingleUserAuthorizer()
        '
        Dim Credentials As SingleUserInMemoryCredentials = New SingleUserInMemoryCredentials

        Credentials.ConsumerKey = "iu0IBsLxxxxxxxxxxxxxxxxxxxxxxtaqQYw"
        Credentials.ConsumerSecret = "RxxxxxxxxxxxxxxxxxxodYxdQ"
        Credentials.OAuthToken = "21xxxxxxxxxxxxxxxxxxG48jK"
        Credentials.AccessToken = "WcxxxxxxxxxxxxxxxxxxwBDI"

        AUTH.Credentials = Credentials

        TWITTERCTX = New TwitterContext(AUTH)

        Try
            AUTH.Authorize()

        Catch ex As Exception
            MsgBox(ex.InnerException)
        End Try

    End Sub

    'BUSQUEDA EN TWITTER
    Private Sub SearchTwitterDemo(ByVal twitterCtx As TwitterContext)
        Try
            RichTextBox1.Clear()

            Dim queryResults = _
            From search In twitterCtx.Search _
            Where search.Type = SearchType.Search _
            And search.Query = TextBox1.Text

            ' Console.WriteLine("Query: " & Environment.NewLine)

            For Each searchResult In queryResults
                For Each entry In searchResult.Statuses
                    RichTextBox1.AppendText( _
                        "User: " & entry.User.Name & Environment.NewLine & _
                        "Screen Name: " & entry.ScreenName & Environment.NewLine & _
                        "Description: " & entry.User.Description & Environment.NewLine & _
                        Environment.NewLine & Environment.NewLine & _
                        "Tweet: " & entry.Text & Environment.NewLine & _
                        "Creado: " & entry.CreatedAt & Environment.NewLine & Environment.NewLine & _
                        "********************** FIN ****************************" & Environment.NewLine & Environment.NewLine)

                Next
            Next
        Catch ex As Exception
            MsgBox(ex.InnerException)
        End Try

    End Sub
I can never show SCREEN NAME and How can I capture all tweets?

Thx any time Mr. Mayo
Coordinator
Oct 21, 2013 at 4:11 PM
You can find UserID and ScreenName on the User.Identifier property. Also, I've written a blog post on Working with Timelines with LINQ to Twitter.

@JoeMayo