Authenticating in VB using VS2010

Topics: Developer Forum, Project Management Forum, User Forum
Dec 28, 2010 at 9:34 PM



I can't seem to get authentication to work in VisualBasic in Visual Studios 2010.  Is there any working example code for this?  The coding for fun articles example does not seem to work for me..





Dec 29, 2010 at 9:00 AM

The coding for fun article, while old, should still work.

Please explain why it does not work and we will try to help.


Dec 29, 2010 at 8:36 PM
Edited Dec 29, 2010 at 8:41 PM

I don't remember exactly what didn't work.. It had something to do with the Auth auth line.. The auto-correct in VS2010 would change it and then riddle it with errors.. My work around is this code, which seems to authenticate me, but when I do my search I still do not get what I am looking for (Original image URL) I am using a flickr pro account... So here is how I am authenticating once I have a FROB..


Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Login.Click

            auth = f.AuthGetToken(tempFrob)
            f.AuthToken = auth.Token
            My.Settings.token = AuthToken
            Me.userNameTxt.Text = auth.User.UserName
            Me.Text = "GetFlickr : " & auth.User.UserName
        Catch ex As FlickrException

        End Try

 Call FindSets()

End Sub

Okay so once I have my token I then call a routine that searched for all sets owned by me.usernametxt.text This is where I am having a problem

    Private Sub FindSets()
        IsLoggedIn = True
        Me.DebugLBL.Text = IsLoggedIn & tempFrob
        My.Settings.tempFrob = tempFrob

        Dim screenName As String = Me.userNameTxt.Text
        Dim user As FoundUser
        Dim userId As String
            user = f.PeopleFindByUserName(screenName)
            userId = user.UserId
            Me.uidLbl.Text = userId
            Dim options As PhotoSearchOptions = New PhotoSearchOptions
            options.UserId = userId
            options.PerPage = 15
            options.Extras = PhotoSearchExtras.All

            ' options.Extras = AuthToken.MyToken
            MyPhotosets = f.PhotosetsGetList(userId)

            PhotoSetGBX.Text = MyPhotosets.Count & " Photo Sets found"

            For x = 0 To MyPhotosets.Count - 1

            StatusLBL.Text = "Done."
        Catch ex As Exception
        End Try
    End Sub

This pulls up all the sets, and I can get URLS, but I am not getting the original urls, which is what I am after, and from what I am reading, this means I am not authenticating correctly. Am I missing something? -Fratm

Dec 30, 2010 at 7:47 AM

Firstly, once you have used a temporary frob calling AuthGetToken again will result in an error.

Secondly, the above code gets a list of photosets - it does not get the images for those photosets, so I don't understand what you mean when you say it doesn't get the 'original urls' as it doesn't get any URLs.

I'm not quite sure what you are doing with the PhotoSearchOptions as PhotosetsGetPhotos does not take that as a parameter.


Dec 30, 2010 at 8:02 AM

Sorry, that code populates a list box with the list of photosets, then I have the following code so when I select a photoset it populates another list box with the photos in that set.. Then when you click a photo, I want it to display in a browser control the URL to the photo, and then print the original URL on a label.. It's confusing, and I posted part of the code.. So here is the rest.

    Private Sub PhotoSetsLBX_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhotoSetsLBX.SelectedIndexChanged

        Dim MyIndex As Integer = PhotoSetsLBX.SelectedIndex
        '    PhotoListGBX.Text = MyPhotosets.Item(MyIndex).Title
        'Catch ex As Exception

        'End Try

        MyPhotoList = f.PhotosetsGetPhotos(MyPhotosets.Item(MyIndex).PhotosetId)
        PhotoListGBX.Text = MyPhotoList.Count & " Photos in set"
        For x = 0 To MyPhotoList.Count - 1

    End Sub


    Private Sub PhotoListLBX_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PhotoListLBX.SelectedIndexChanged
        Dim MyIndex As Integer = Me.PhotoListLBX.SelectedIndex
        Dim MyURL As String

        If Me.LightBoxCBX.CheckState = CheckState.Checked Then
            MyURL = MyPhotoList.Item(MyIndex).WebUrl & "lightbox"
            If IsLoggedIn Then
                MyURL = MyPhotoList.Item(MyIndex).OriginalUrl
                MyURL = MyPhotoList.Item(MyIndex).LargeUrl
            End If

        End If
        Me.PhotoDescriptionLBL.Text = MyPhotoList.Item(MyIndex).Title

        ' Figure out which photo is available and display the highest res version.

        StatusLBL.Text = MyPhotoList.Item(MyIndex).OriginalUrl & "  Original Image"

    End Sub

The sub above this line is the one that is not returning the orginalurl.. Some how I am losing my authentication.. I only call AuthGetToken once during this process. So I know it will result in an error when using the temporary frob.

Dec 30, 2010 at 8:05 AM

I guess what I am asking is, what should I be passing to PhotosetsGetPhotos to show that I am authenticated, in order for MyPhotoList(MyIndex).originalUrl to return a value.



Dec 30, 2010 at 8:18 AM

By the way, this is the code in the coding for fun article that does not work in VS2010

    ' Create Flickr instance
    Dim f As Flickr = New Flickr(ApiKey, SharedSecret)    
        ' use the temporary Frob to get the authentication
        Auth a = f.AuthGetToken(tempFrob)
        ' Store this Token for later usage, 
        ' or set your Flickr instance to use it.
        Console.WriteLine("User authenticated successfully")
        Console.WriteLine("Authentication token is " & a.Token)
        f.ApiToken = a.Token
Console.WriteLine("User id is " & a.UserId)
    Catch ex As FlickrException

        ' If user did not authenticat your application 
        ' then a FlickrException will be thrown.
        Console.WriteLine("User did not authenticate you")
    End Try

if you enter it exactly as showen above (Which is from the article) VS tries to auto correct the Auth A= f.AuthGetToken(tempFrob) to look like this :

auth(a = f.AuthGetToken(tempFrob))

And it puts a blue squiggle under auth, and a red squiggle under a, auth comes up with "Expression is not a method" and the a come up with a red ! with nothing next to it. I think my code works around that, but it's confusing to a noobie like me :) -Steve

Dec 30, 2010 at 8:28 AM

You need to pass the PhotoSearchExtras parameter to the call to PhotosetsGetPhotos, e.g.

MyPhotoList = f.PhotosetsGetPhotos(MyPhotosets.Item(MyIndex).PhotosetId, PhotoSearchExtras.AllUrls)

You are correct about the error in the coding for fun article. The line in question is written as C#, not VB.Net. It should be as follows:

Dim a As Auth = f.AuthGetToken(tempFrob)

Hope this helps




Dec 30, 2010 at 11:14 PM

That worked, thanks for your help!