Call Google Tiny URL API in MATLAB
37 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Chi
el 19 de En. de 2018
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);
1 comentario
Ver también
Categorías
Más información sobre Google en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!