This article shows how to use photo id for Flickr object in Microsoft Small Basic programming language.


Photo ID

Flickr.GetPictureOfMoment() or Flickr.GetRandomPicture() return following format of URLs.

https://farm{farm-id}.static.flickr.com/{server-id}/{photo-id}_{secret}.jpg

But the URL above shows only photo image.  Other information such as the author and copyright can be obtain with following format.

http://flickr.com/photo.gne?id={photo-id}

Following sample code is to get photo ID from the URL provided by the Flickr object.

Sub Url2Id
  ' param url
  ' return id - photo id
  p = Text.GetIndexOf(url, "_") - 1
  id = ""
  c = Text.GetSubText(url, p, 1)
  While c <> "/"
    id = Text.Append(c, id)
    p = p - 1
    c = Text.GetSubText(url, p, 1)
  EndWhile
EndSub

Base 58 Photo ID

Short URL is short version of URL that may be useful for using in SNS.

https://flic.kr/p/{base58-photo-id}

Following sample code is for base 58 encoding.

Sub Base58Encode
  ' param id - photo id
  ' return encoded - base58 photo id
  alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
  base = Text.GetLength(alphabet)
  encoded = ""
  While 0 < id
    mod = Math.Remainder(id, base)
    encoded = Text.Append(Text.GetSubText(alphabet, mod + 1, 1), encoded)
    id = Math.Floor(id / base)
  EndWhile
EndSub

Following sample code is for base 58 decoding.

Sub Base58Decode
  ' param encoded - base58 photo id
  ' return id - photo id
  alphabet = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"
  base = Text.GetLength(alphabet)
  len = Text.GetLength(encoded)
  id = 0
  place = 1
  For p = len To 1 Step -1
    id = id + place * (Text.GetIndexOf(alphabet,Text.GetSubText(encoded, p, 1)) - 1)
    place = place * base
  EndFor
EndSub

Sample Programs

Screen Shot

Following screen shot is by the program Flickr Sample 0.5 above.

Credit

Original photo by Stéphane Gérard (CC BY-NC-SA 2.0)


See Also

Other Resources