API URL shortening service from Vk.cc

API URL shortening service from Vk.cc


I'm working on the API URL shortening service for VK.cc, which is used by Vkontakte (Russian social network) users for sharing URLs. I started with https://github.com/vitvak/vk-api-url-shortener and got a working prototype in a few hours: vk_shrink - http://shrink.herokuapp.com/.

It's not an official service from Vkontakte, so it doesn't have any guarantee to work well or at all :) It's just a simple HTTP server which uses [VK API](https://vk.com/dev/method#GET_send_intermediate_share_link) to shorten any URL.

HTTP GET/POST parameters:

VK API key - your_api_key from https://vk.com/dev/method#GET_application_list 

URL to shorten - a full URL, for example http://shrink.herokuapp.com/u12134627 

Title - a short description of the link, is shown as tooltip when you hover over shortened link Link preview length - how many characters from title will be used as link preview in social networks (Twitter will cut it anyway), set to 0 for unlimited preview Show perma-link? - if yes then show 'permalink' instead of just generated short url Perma-link name - what you want displayed after 'permalink' - can be anything from domain name, blog title to 'via @vkontakte'


If you have a working Vk.com API key and want to use it with vk_shrink, send me an email at [email protected] or open issue on https://github.com/vitvak/vk-api-url-shortener - I'll publish your key as 'test key'. Also if you know how to write a decent HTML parser (with regexps) for parsing titles and descriptions please do that :) And of course forks are welcome!

Vk_shrink runs on Heroku free plan which has 512MB RAM limit so it may crash if you try to shorten too many (or rather: too long) URLs on your first try. You can increase that limit with some hacks - see https://devcenter.heroku.com/articles/heroku-memory for details and don't forget to read about Heroku free dyno sleeping :-)


My other articles: http://vitvak.me/articles/ Follow Follow @Vit_tokarev on Twitter Reply Delete

How do I change where it says "via VKontakte" at the end of the shortened url? It's using my username and not my full name and it uses Cyrillic characters which is ugly as hell.. Thanks for this awesome service though, just in need to fix that part. Reply Delete

Hi! Thanks for the feedback. I'll update it once I get more free time :) Delete

I appreciate your article post.Really thank you! Much obliged. Reply Delete

This service is fantastic, but please change the default permalink format from /u12134627 to /vitvak instead of my username. Thanks again for creating this!!! Reply Delete

Hi Vito, thanks a lot for sharing this tool with us :) It's incredibly useful, perfect work :-) My only problem is that when I use it on Safari (both Desktop and iOS), it doesn't generate any preview of URL before sending me to VK page where I can see the preview... Is there anything i can change in the code to fix that? Thanks! Reply Delete

Hi, thanks for sharing. The service seems down though.. whois vk_shrink.herokuapp.com shows it's expired now. Is this just temporary or did something happen? Might be worth mentioning on the github page... Reset Reply Delete

It looks like heroku free account gets automatically reseted after app has been idle for 30 days (as stated here https://devcenter.heroku.com/articles/dyno-sleep#what-if-i-need-my-application-to-be-always-up). For now I have migrated it to my low traffic VPS server which works 24x7 without getting suspended.. Delete

Thanks for the comment. Just updated to heroku-1. Heroku is more of a hobby than anything else, so please don't expect too much from it :) Delete

apparently there is no API that can be used to get group members list (using api key). am I correct? "List all Russian VK Groups where user can become member" Reply Delete

Hi, thanks for your feedback! Yes, unfortunately only page lists are available via vk api... But you could try https://vk.com/dev/login?return_to=%2Ffriends which should return friends (or me) list in json format; maybe you can parse groups this way? Or you know how to work with HTML parser (I hacked htmlparser.py for this purpose, but it's quite slow and not too reliable)? Delete

As I understand there is no API for doing that. The only way to get it would be writing bot which scans groups. Reply Delete

And if you know how to work with HTML parser (I hacked htmlparser.py for this purpose, but it's quite slow and not too reliable) - all you need is just something like: https://github.com/vitvak/vk-api-url-shortener/blob/master/vk_shrink/utils/groups_to_usernames.py Reply Delete

Hi Vit! Looks like the service ran out of free dynos. I have no experience with heroku, is there a way to add more dynos? Thanks for your effort in maintaining this btw! Reply Delete

Sorry about that, the service was suspended because I had forgotten to update DNS records after changing my app's hostname. It should be working now , please let me know if you still have problems with it. Thanks! Delete

Hi Vito, thanks a lot for sharing this tool :) Now, when it works again (for some reason it didn't work before), could you make it treat series of underscores (_) as spaces? So like if I write "_this_is_a_series" then get "vitvak" back instead of "vitovak", because "this_is_a_series" would be too long. Reply Delete

Hi again! Yes, I know about this issue; it's an htmlparser.py bug (see my comment on oct 25th). Currently there is no workaround for that :( I'm looking into it, might take some time though.. Delete

Hello again! Thanks for your reply :) Just checked out htmlparser.py and saw that you've already noticed the problem with underscores... But it looks like you're not planning to fix it any time soon? Any chance of at least making underscores optional? So whenever user writes only 3 consecutive underscores (or 4 or 5 etc), server would ignore them all together (whatever number of underscores passed)? Thank you very much for your time! Reply Delete

Hi again Vit! Sorry for not replying sooner. To be honest I didn't think of that option, but it does sound like a good idea.. Migrated to Heroku based on your suggestion, added underscores option (removed polling :( , though you could still do it by making multiple requests...), changed links etc. Please let me know if anything doesn't work as expected :) Reset Reply Delete

Great news! Thanks a lot. Unfortunately it seems the underscores are not ignored even when there is only single underscore in user input... Usually they aren't problem since people usually write space after them and space represents "_" in VK API (unless there is no space at all) but sometimes people make typos and write two underscores in a row. Here is an example: "this_is_a_series" - should be "this is a series". But on the other hand, if they both would represent "_" then it would be impossible to search by hashtags which contain underscores... Will give your service a try at some point! Thanks again :) Delete

We are social