API to convert URLs


(Tinyfriends) #1

Hello,

Is there an API to convert skfb.ly to sketchfab.com URLs? (Couldn’t find any). If not, I think it would be a great feature to add.

Edit: the reason for that is that we have stored many skfb.ly URLs in our database, but we cannot extract the model ID from those links. So we need to convert all our links.

Thanks.
Tinyfriends.


(Paul Sketch) #2

Hello,

Did you try using http headers and code ?
see https://stackoverflow.com/questions/4201062/how-can-i-unshorten-a-url
or
https://github.com/ryanfox/unshorten.py/blob/master/unshorten.py


(Tinyfriends) #3

Thank you I will test that.


#4

You could potentially use our oEmbed endpoint, which supports skfb.ly links, but you would have to parse the response with a somewhat awkward regex to get the model ID, maybe getting it from the thumbnail URL would be easiest…

https://sketchfab.com/oembed?url=https://skfb.ly/6B9tQ

{
"author_name": "Ed Gonzalez-Tennant",
"author_url": "https://sketchfab.com/edgonzaleztennant",
"provider_name": "Sketchfab",
"width": 640,
"thumbnail_width": 720,
"html": "<div class=\"sketchfab-embed-wrapper\"><iframe height=\"360\" webkitallowfullscreen=\"true\" onmousewheel=\"\" allowfullscreen=\"\" width=\"640\" src=\"https://sketchfab.com/models/087f11bba4e44645885071b64d5db51b/embed\" mozallowfullscreen=\"true\" class=\"\" frameborder=\"0\" allow=\"autoplay; fullscreen; vr\" allowvr=\"\"></iframe>\n\n<p style=\"font-size: 13px; font-weight: normal; margin: 5px; color: #4A4A4A;\">\n    <a href=\"https://sketchfab.com/models/087f11bba4e44645885071b64d5db51b?utm_campaign=087f11bba4e44645885071b64d5db51b&utm_medium=embed&utm_source=oembed\" target=\"_blank\" style=\"font-weight: bold; color: #1CAAD9;\">Evolution of Hominins (aka March of Progress)</a>\n    by <a href=\"https://sketchfab.com/edgonzaleztennant?utm_campaign=087f11bba4e44645885071b64d5db51b&utm_medium=embed&utm_source=oembed\" target=\"_blank\" style=\"font-weight: bold; color: #1CAAD9;\">Ed Gonzalez-Tennant</a>\n    on <a href=\"https://sketchfab.com?utm_campaign=087f11bba4e44645885071b64d5db51b&utm_medium=embed&utm_source=oembed\" target=\"_blank\" style=\"font-weight: bold; color: #1CAAD9;\">Sketchfab</a>\n</p>\n</div>",
"thumbnail_url": "https://media.sketchfab.com/urls/087f11bba4e44645885071b64d5db51b/dist/thumbnails/a2400279d49449e1a1567953e1bac20f/3914ec427cd54096b1efa61ec6c9d6c7.jpeg",
"version": "1.0",
"height": 360,
"thumbnail_height": 405,
"provider_url": "https://sketchfab.com",
"type": "rich",
"title": "Evolution of Hominins (aka March of Progress)"
}

#5
$.get('https://sketchfab.com/oembed?url=https://skfb.ly/6B9tQ')
    .then(function(response){
        window.console.log(response.thumbnail_url.match(/[a-z0-9]{32}/)[0]);
    });

// 087f11bba4e44645885071b64d5db51b