Results 1 to 8 of 8

Thread: VB6 Flickr API - Open To Everyone

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Location
    London
    Posts
    76

    Post VB6 Flickr API - Open To Everyone

    Hi all dear fellows VB6 Programmers,

    A bit of introduction:
    Sometime ago, I ventured to develop a module to my Document Management System.
    With this module I could manage my own photographs, by indexing my own data fields, storing (in a structured local folders), adding Keywords(Tags) from about 1M ISO standardized keywords tree, adding geolocation (Google Maps Integration), saving IPCT/Exif (exiftool) Copyright and Data into image file, uploading the image to Flickr, keeping track of views, faves, comments and my photos chosen to be featured in the Flickr Explorer and/or galleries, and lastly keeping a backup of it all locally and in the cloud. Also, I wanted to manage my Flickr contacts’ photos updates, photos I’ve viewed, skipped or faved/commented.
    At that point in time, I did a strenuous research into flickr’s API but ended up without any reference material for VB6, the only one reference I found was a Flickr’s group which seemed to be dead since 2008 (I think), apart from that I could not find anything to start from, and my last resource was using the browser-control to collect/process the data I required for doing all this stuff. A couple of weeks ago I started a thread in this forum asking for help to solve an issue, what leaded me to another thread from another user; When user Olaf Schmidt came up with one solution that would open the possibility to me to use the proper Flickr’s API rather than using “Tricks” to collect data. Anyway, the only one bad side, Olaf was proposing to use his proprietary Library, what I did not like.

    Since then, I’m working in this class module that allows me to use Flickr’s API without any external 3rd party libraries. So, my idea is to share with who might be interested. This thread is open to anyone who want to participate sharing and helping in this little task.
    The following code is free to you use as you will, but I hope that if you learn something new you come back and share with us.

    This is the version 0 and cover only 3 flickr’s methods, but soon, I hope, we will cover all Flickr’s API methods.

    Is there any VB6 developer who also love photography and has it as a hobby (or alternative business?)?

    So, here we go,

    Thanks to all you guys who replied to my threads, posted positive comments and helped me to take this step.

    Thanks for any feedbacks, critiques and suggestions.
    MBS.


    Code:
    '*******************************
    'PROJECT REFERENCES: MICROSOFT XML 6.0 (msxml6.dll)
    '*******************************
    
    '*******************************
    ' DECLARATIONS
    Public c_FlickrAPI As New Flickr_API_Class
    Public flickr_APIkey As String
    
    Public xXML As New MSXML2.DOMDocument
    Public xXML_Parsed As New MSXML2.DOMDocument
    Public xml_Nodes As MSXML2.IXMLDOMNodeList
    Public xml_Node As MSXML2.IXMLDOMNode
    
    Private Sub Form_Load()
    
        flickr_APIkey = "6a669c22eae9c3cc0c4bc67a26f2b1ce"
        ' YOU WILL NEED YOUR OWN APIKEY
        ' OR USE A TEMPORAY KEY LIKE THE ONE ABOVE, THESE TEST APIKEY ONLY WORKS UNTIL 23:59h OF THE DAY YOU ACQUIRED IT
        ' TO GET A TEMPORAY APIKEY
        ' 1 - GO TO: https://www.flickr.com/services/api/explore/flickr.test.echo
        ' 2 - CHECK THE OPTION: [Sign call with no user token?]
        ' 3 - HIT [CALL METHOD]
        ' 4 - RETRIEVE THE APIKEY FROM THE RESPONSE
        '<api_key>6a669c22eae9c3cc0c4bc67a26f2b1ce</api_key>
    
        FlickerExplorer
        
    End Sub
    
    Private Sub FlickerExplorer()
    
        ' BASICLY CALLING THE FLICKR API FUNCTIONS / METHODS ARE ALL THE SAME, FIND NEXT HOW TO
        
        ' CALLING THE flickr_Explorer_GetPhotos from FLICKR APIs
    
        xXML.loadXML c_FlickrAPI.flickr_Explorer_GetPhotos()
        Set xml_Nodes = xXML.SelectNodes("/methodResponse/params/param/value/string")
        
        If xml_Nodes Is Nothing Then Stop ' DID NOT GET THE NODES PROPERLY
        If InStr(1, xXML.Text, "faultCode") <> 0 Then Stop ' SOMETHING ELSE WENT WRONG
        
        ' THE XML-RPC STORE THE XML DATA INTO A [escaped-xml-payload] WITHIN THE [string] NODE
        ' SO WE GET THE FULL XML TO PARSE THE ROOT NODES AND THEN LOADXML FROM THE XML.TEXT,
        ' TO GET THE PARSED XML WITH PHOTOS NODES.
        '
        ' OF COURSE YOU CAN CODE A FUNCTION/SUB TO DO IT, I DID NOT DO IT YET, BECAUSE I'M TOO LAZY LOL
        ' THE XML-RPC STRUCTURE CAN BE FOUND HERE: https://www.flickr.com/services/api/response.xmlrpc.html
    
        xXML_Parsed.loadXML xml_Nodes.Item(0).Text
        Set xml_Nodes = xXML_Parsed.SelectNodes("/photos/photo")
        
        If xml_Nodes Is Nothing Then Stop ' DID NOT GET THE NODES PROPERLY
        If InStr(1, xXML.Text, "faultCode") <> 0 Then Stop ' SOMETHING ELSE WENT WRONG
        
        For Each xml_Node In xml_Nodes
            
            ' TO GET ITEMS DATA JUST CALL xml_Node.SelectSingleNode AS FOLLOW
            
            vm_PHOTOID = xml_Node.SelectSingleNode("@id").Text ' PHOTO/ITEM ID
            If Not IsNumeric(vm_PHOTOID) Then Stop 'SOMETHING WENT WRONG
            
            vm_UserID = xml_Node.SelectSingleNode("@owner").Text ' ITEM USER OWNER
            If InStr(1, vm_UserID, "@") = 0 Then Stop  'SOMETHING WENT WRONG
            
            vm_URLtIMG = xml_Node.SelectSingleNode("@url_t").Text 'ITEM THUMBNAIL URL
    
            vm_TITIMG = xml_Node.SelectSingleNode("@title").Text 'ITEM TITLE
            
        Next
    End Sub
    Code:
    '*************************************************
    ' FLICKR API LIBRARY: NAME: Flickr_API_Class
    ' BY: MBS - ON: 27/09/2017
    ' LICENSE: DO WHATEVER YOU WANT TO IT, AT YOUR OWN RISK ;-)
    '
    ' THANKS TO: OLAF SCHMIDT
    '*************************************************
    ' V.0 - 27/09/2017
    ' THREE FUNCTIONS AKA FLICKR METHODS:
    ' flickr_People_GetPhotos           =   .people.getPhotos                   = Return photos from the given user's photostream
    ' flickr_Explorer_GetPhotos         =   .interestingness.getList            = Returns the list of interesting photos (AKA EXPLORER) for the most recent day or a user-specified date
    ' flickr_GetListRecentlyUploaded    =   .contacts.getListRecentlyUploaded   = Return a list of contacts for a user who have recently uploaded photos
    '
    ' AND I'M WORKING ON THE NEW OAUTH AUTHENTICATION METHODS (A SERIE OF OTHER API METHODS REQUIRE AUTHENTICATION)
    ' IF YOU HAVE ALREADY WALKED ON THIS LANDS, YOU ARE MOST WELCOME TO JOIN AND SHARE
    ' FLICKR/OATH AUTHENTICATION DOCUMENTATION: https://www.flickr.com/services/api/auth.oauth.html
    
    Option Explicit
    
    Public flickr_APIkey As String 'I WOULD SUGGEST YOU TO DECLARE flickr_APIkey IN YOUR GENERAL DECLARATIONS MODULE "MODULE1.BAS"
    
    Public Function flickr_People_GetPhotos(p_UserNSID, Optional p_per_page As Long = 500, Optional p_page As Long = 1, Optional p_extras As String = "url_o,url_k,url_h,url_b,url_c,url_z,url_m,url_t") As String
      ' I WILL COMMENT ONLY THIS FUNCTION, EVERY OTHER HAS BASICLY THE SAME PARAMETERS AND FUNCTIONALITY
      ' FOR MORE DETAILS ON EACH METHOD GO TO: https://www.flickr.com/services/api/
      '
      ' p_UserNSID = REQUIRED, FLICKR USER NSID TO GET ITEMS (TO FIND DOCUMENTATION FOR USERNSID: https://www.flickr.com/services/api)
      ' p_per_page = OPTIONAL, NUMBER OF ITEMS (PHOTOS,VIDEOS ETC) RETURNED IN ONE PAGE, THE DEFAULT IS 500 ITEMS AND ALSO IT'S THE MAXIMUM VALUE PER PAGE
      ' p_page = OPTIONAL, PAGE NUMBER TO GET ITEMS (IF USER HAS 500+ ITEMS, IT WILL BREAK IN TWO OR MORE PAGES (500 ITEM PER PAGE) / DEFAULT = 1
      ' p_extras = OPTIONAL, RETURN THE URL FOR THE MOST COMMON IMAGES SIZES, THE DEFAULT IS WHAT I USE MOST, BUT YOU CAN CHANGE IT AT YOUR WILL.
      ' I SUPRESSED A FEW PARAMENTERS IN THIS FUNCTION, PARAMETER THAT I NEVER USE, BUT IF YOU WAT TO ADD ANY OTHER JUST FIND FULL DOCMENTATION IN
      ' FLICKR METHOD AND ARGUMENTS PAGE: https://www.flickr.com/services/api/...getPhotos.html
      
      ' THE FOLLOWING CALL USES THE NATIVE WinHttpRequest object TO EXECUTE FLICKR API METHOD
      '
      ' THE RESPONSE FORMAT format=xmlrpc - CAN BE CHANGED: FLICKR AVAILABLE RESPONSE FORMATS ARE: REST, XML-RPC, SOAP, JASON and PHP
      ' I'VE CHOOSE XML BECAUSE I CAN USE NATIVE (MICROSOFT) XML OBJECTS/PARSER NOT REQUIRING ANY EXTERNAL PARSER
      ' IF YOU WANT YOU CAN CHANGE THE RESPONSE FORMAT AND WORK AS YOU WILL, FOR DOCMENTATION FOR RESPONSE FORMATS: https://www.flickr.com/services/api/
      
      With CreateObject("WinHttp.WinHttpRequest.5.1")
          .Open "GET", "https://api.flickr.com/services/rest/?format=xmlrpc&method=flickr.people.getPhotos" & _
                "&api_key=" & flickr_APIkey & _
                "&user_id=" & p_UserNSID & _
                "&extras=" & p_extras & _
                "&per_page=" & p_per_page & _
                "&page=" & p_page, False
          .send
          If .Status = 200 Then flickr_People_GetPhotos = .responseText: Exit Function
          ' IF STATUS = 200 = HTTP_STATUS_OK = THEN RETURN FULL XML
          
          flickr_People_GetPhotos = "Fail: " & .StatusText
          ' IF STATUS = ANYTHING ELSE, SOMETHING WENT WRONG, YOU CAN CRITIQUE THE FAIL ERRORS CODE IF YOU WANT.
          ' FIND STATUS CODE HERE: https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
          
      End With
      
    End Function
    
    Public Function flickr_Explorer_GetPhotos(Optional p_per_page As Long = 500, Optional p_page As Long = 1, Optional p_extras As String = "url_o,url_k,url_h,url_b,url_c,url_z,url_m,url_t") As String
      
      With CreateObject("WinHttp.WinHttpRequest.5.1")
          .Open "GET", "https://api.flickr.com/services/rest/?format=xmlrpc&method=flickr.interestingness.getList" & _
                "&api_key=" & flickr_APIkey & _
                "&extras=" & p_extras & _
                "&per_page=" & p_per_page & _
                "&page=" & p_page, False
          .send
          If .Status = 200 Then flickr_Explorer_GetPhotos = .responseText: Exit Function
          flickr_Explorer_GetPhotos = "Fail: " & .StatusText
      End With
      
    End Function
    
    Public Function flickr_GetListRecentlyUploaded(p_date_lastupload As Long, Optional p_filter As String = "all") As String
      
      With CreateObject("WinHttp.WinHttpRequest.5.1")
          .Open "GET", "https://api.flickr.com/services/rest/?format=xmlrpc&method=flickr.contacts.getListRecentlyUploaded" & _
                "&api_key=" & flickr_APIkey & _
                "&date_lastupload=" & p_date_lastupload & _
                "&filter=" & p_filter & "&auth_token=72157687241136323-f465a033e87d8d0f", False
                                        'YOU HAVE TO GET A NEW auth_token ON EVERY SINGLE CALL
          .send
          If .Status = 200 Then flickr_GetListRecentlyUploaded = .responseText: Exit Function
          flickr_GetListRecentlyUploaded = "Fail: " & .StatusText
      End With
    
    End Function
    PS: I DON'T KNOW WHY MY CODE FORMAT DOESN'T GET COLOURS AS I'VE SEEN IN ANOTHER POSTS?
    Last edited by MBS; Sep 27th, 2017 at 03:24 PM.
    MBS

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: VB6 Flickr API - Open To Everyone

    Nice work, thanks for sharing I think it should be in the Codebank section though since it is a working demo.
    Last edited by jpbro; Sep 27th, 2017 at 03:42 PM.

  3. #3
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    38,989

    Re: VB6 Flickr API - Open To Everyone

    Sure looks like a good CodeBank submission, to me, so I moved it.
    My usual boring signature: Nothing

  4. #4
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: VB6 Flickr API - Open To Everyone

    Quote Originally Posted by MBS View Post
    ...
    PS: I DON'T KNOW WHY MY CODE FORMAT DOESN'T GET COLOURS AS I'VE SEEN IN ANOTHER POSTS?
    If you just use the Code tag it is formatted with a fixed space font, but not color highlighted.
    (i.e. you select the code text and press the button with the "#" above the reply box).
    If you use the HIGHLIGHT=vb (or some other language) tag, you will get highlighting.
    (i.e. you selct the code text and press the button with the "VB" text in it (looks like "VE" in a lot of browsers) and typed in a language name).
    vb Code:
    1. '*******************************
    2. 'PROJECT REFERENCES: MICROSOFT XML 6.0 (msxml6.dll)
    3. '*******************************
    4.  
    5. '*******************************
    6. ' DECLARATIONS
    7. Public c_FlickrAPI As New Flickr_API_Class
    8. Public flickr_APIkey As String
    9.  
    10. Public xXML As New MSXML2.DOMDocument
    11. Public xXML_Parsed As New MSXML2.DOMDocument
    12. Public xml_Nodes As MSXML2.IXMLDOMNodeList
    13. Public xml_Node As MSXML2.IXMLDOMNode
    14.  
    15. Private Sub Form_Load()
    16.  
    17.     flickr_APIkey = "6a669c22eae9c3cc0c4bc67a26f2b1ce"
    18.     ' YOU WILL NEED YOUR OWN APIKEY
    19.     ' OR USE A TEMPORAY KEY LIKE THE ONE ABOVE, THESE TEST APIKEY ONLY WORKS UNTIL 23:59h OF THE DAY YOU ACQUIRED IT
    20.     ' TO GET A TEMPORAY APIKEY
    21.     ' 1 - GO TO: [url]https://www.flickr.com/services/api/explore/flickr.test.echo[/url]
    22.     ' 2 - CHECK THE OPTION: [Sign call with no user token?]
    23.     ' 3 - HIT [CALL METHOD]
    24.     ' 4 - RETRIEVE THE APIKEY FROM THE RESPONSE
    25.     '<api_key>[B]6a669c22eae9c3cc0c4bc67a26f2b1ce[/B]</api_key>
    26.  
    27.     FlickerExplorer
    28.    
    29. End Sub
    30.  
    31. Private Sub FlickerExplorer()
    32.  
    33.     ' BASICLY CALLING THE FLICKR API FUNCTIONS / METHODS ARE ALL THE SAME, FIND NEXT HOW TO
    34.    
    35.     ' CALLING THE flickr_Explorer_GetPhotos from FLICKR APIs
    36.  
    37.     xXML.loadXML c_FlickrAPI.flickr_Explorer_GetPhotos()
    38.     Set xml_Nodes = xXML.SelectNodes("/methodResponse/params/param/value/string")
    39.    
    40.     If xml_Nodes Is Nothing Then Stop ' DID NOT GET THE NODES PROPERLY
    41.     If InStr(1, xXML.Text, "faultCode") <> 0 Then Stop ' SOMETHING ELSE WENT WRONG
    42.    
    43.     ' THE XML-RPC STORE THE XML DATA INTO A [B][escaped-xml-payload][/B] WITHIN THE [B][string][/B] NODE
    44.     ' SO WE GET THE FULL XML TO PARSE THE ROOT NODES AND THEN LOADXML FROM THE XML.TEXT,
    45.     ' TO GET THE PARSED XML WITH PHOTOS NODES.
    46.     '
    47.     ' OF COURSE YOU CAN CODE A FUNCTION/SUB TO DO IT, I DID NOT DO IT YET, BECAUSE I'M TOO LAZY LOL
    48.     ' THE XML-RPC STRUCTURE CAN BE FOUND HERE: [url]https://www.flickr.com/services/api/response.xmlrpc.html[/url]
    49.  
    50.     xXML_Parsed.loadXML xml_Nodes.Item(0).Text
    51.     Set xml_Nodes = xXML_Parsed.SelectNodes("/photos/photo")
    52.    
    53.     If xml_Nodes Is Nothing Then Stop ' DID NOT GET THE NODES PROPERLY
    54.     If InStr(1, xXML.Text, "faultCode") <> 0 Then Stop ' SOMETHING ELSE WENT WRONG
    55.    
    56.     For Each xml_Node In xml_Nodes
    57.        
    58.         ' TO GET ITEMS DATA JUST CALL xml_Node.SelectSingleNode AS FOLLOW
    59.        
    60.         vm_PHOTOID = xml_Node.SelectSingleNode("@id").Text ' PHOTO/ITEM ID
    61.         If Not IsNumeric(vm_PHOTOID) Then Stop 'SOMETHING WENT WRONG
    62.        
    63.         vm_UserID = xml_Node.SelectSingleNode("@owner").Text ' ITEM USER OWNER
    64.         If InStr(1, vm_UserID, "@") = 0 Then Stop  'SOMETHING WENT WRONG
    65.        
    66.         vm_URLtIMG = xml_Node.SelectSingleNode("@url_t").Text 'ITEM THUMBNAIL URL
    67.  
    68.         vm_TITIMG = xml_Node.SelectSingleNode("@title").Text 'ITEM TITLE
    69.        
    70.     Next
    71. End Sub

  5. #5
    Hyperactive Member
    Join Date
    Jun 2016
    Location
    EspaƱa
    Posts
    506

    Re: VB6 Flickr API - Open To Everyone

    Hi, I have a problem generate the apikey but I get the error "faultCode 100 faultString Invalid API Key (Key has invalid format)"

    I really like your initiative and I also like the apis this serves me a lot to learn I would like you to continue with it.
    A greeting, sorry, my bad English.

    PD:
    the problem is solved c_FlickrAPI.flickr_APIkey = "55cb210d36fe7ae8c03cdf67d63f6f1f"
    Last edited by yokesee; Sep 28th, 2017 at 06:53 PM.

  6. #6
    Fanatic Member
    Join Date
    Aug 2016
    Posts
    673

    Re: VB6 Flickr API - Open To Everyone

    have a bug

    flickr_APIkey = "6a669c22eae9c3cc0c4bc67a26f2b1ce"

    to:

    c_FlickrAPI.flickr_APIkey = "6a669c22eae9c3cc0c4bc67a26f2b1ce"

    o.

    Someone has already pointed out

    can used api to upload pic
    Last edited by xxdoc123; Sep 29th, 2017 at 03:55 AM.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 1999
    Location
    London
    Posts
    76

    Re: VB6 Flickr API - Open To Everyone

    Hi Guys, first, sorry for the delay to reply you all.

    Quote Originally Posted by jpbro View Post
    Nice work, thanks for sharing I think it should be in the Codebank section though since it is a working demo.
    Quote Originally Posted by Shaggy Hiker View Post
    Sure looks like a good CodeBank submission, to me, so I moved it.
    @jpbro and @Shaggy Hiker, THANKS SO MUCH GUYS, I'm so pleased to have this thing select to the CodeBank. THANKS AGAIN!

    Quote Originally Posted by passel View Post
    If you just use... <HIGHLIGHT=vb>...
    @passel, Thanks mate, Will use next time!

    Quote Originally Posted by yokesee View Post
    Hi, I have a problem generate the apikey but I get the error "faultCode 100 faultString Invalid API Key (Key has invalid format)"
    I really like your initiative and I also like the apis this serves me a lot to learn I would like you to continue with it.
    A greeting, sorry, my bad English.
    PD:
    the problem is solved c_FlickrAPI.flickr_APIkey = "55cb210d36fe7ae8c03cdf67d63f6f1f"
    @yokesee, Thanks so much my friend, Glad you got it working. Remember if you are using testing API Keys, you have get a new one everyday. If you get your own APIKey keep it to yourself, do not share it.

    Quote Originally Posted by xxdoc123 View Post
    have a bug
    flickr_APIkey = "6a669c22eae9c3cc0c4bc67a26f2b1ce"
    to:
    c_FlickrAPI.flickr_APIkey = "6a669c22eae9c3cc0c4bc67a26f2b1ce"
    o.
    Someone has already pointed out
    can used api to upload pic
    @xxdoc123, Hey mate, there is NO BUG, if you properly read my comment you will find:
    Public flickr_APIkey As String 'I WOULD SUGGEST YOU TO DECLARE flickr_APIkey IN YOUR GENERAL DECLARATIONS MODULE "MODULE1.BAS"

    flickr_APIkey is a string variable that holds your APIKey(read comments above) to be used along the API functions/methods.
    Answering your question, yes, I'm working on API Auth that will allow us to upload photos.


    To All:
    1 - Please READ MY CODE COMMENTS.

    2 - I'm in an advanced stage with Flick OAUTH (Authentication), hopefully will post something in the next couple of days...

    Thanks again you all,
    Talk soon.
    MBS
    MBS

  8. #8
    New Member
    Join Date
    Aug 2018
    Posts
    1

    Re: VB6 Flickr API - Open To Everyone

    hi mbs,

    this tool seems to be perfect for my needs.

    i would like to download from my own stream all available metadata to synchronise them with my local pictures. and i would love to update metadata on the server as well. ideally i would love to maintain these data in an excel-sheet and from there i would love to be able to trigger changes (title, date-taken, etc.)

    i could not get your code to run - so where could i download your working demo to try it?

    thank you, leo.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width