Call Google Tiny URL API in MATLAB
37 次查看(过去 30 天)
显示 更早的评论
Hi everyone,
I am trying to call Google URL Shortener API https://developers.google.com/url-shortener/v1/getting_started#actions in MATLAB to shorten an URL. I know that I can go to https://goo.gl/ and manually paste the long URL into the text box. But I am wondering if I can do that programatically in MATLAB.
I know very little about web programming and this is as far as I can get,
options = weboptions('RequestMethod','post');
data = webread('https://www.googleapis.com/urlshortener/v1/url', 'longUrl', 'http://www.google.com/', options)
Error using readContentFromWebService (line 45)
The server returned the status 400 with message "Bad Request" in response to the request to URL https://www.googleapis.com/urlshortener/v1/url.
Error in webread (line 122)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
0 个评论
回答(1 个)
Chi
2018-1-19
First, you should have a URL shortener API key. It can be generated in the Google 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);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Google 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!