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.
PS: I DON'T KNOW WHY MY CODE FORMAT DOESN'T GET COLOURS AS I'VE SEEN IN ANOTHER POSTS?
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