Bitly

Bitly API document: /v3/shorten

Matlab code:

url  = 'https://api-ssl.bitly.com/v3/shorten?access_token={your_access_token}&format=txt&longUrl=http://google.com/';
shortened = webread(url)

Escape character is also supported / 支持转义字符:

url  = 'https://api-ssl.bitly.com/v3/shorten?access_token={your_access_token}&format=txt&longUrl=http%3A%2F%2Fgoogle.com%2F';
shortened = webread(url)

Google

Google API document: URL Shortener

First, you should have a URL shortener API key. It can be generated in the Credentials page.

Then, the matlab code:

url='https://www.googleapis.com/urlshortener/v1/url?key={yours}';
options = weboptions('RequestMethod','post', 'MediaType','application/json');
Body = struct('longUrl', 'http://www.google.com/');
response = webwrite(url, Body, options);

Note:确保你的MATLAB可以科学上网(Preferences->Web->Internet connection里设置use a proxy)。