client_id = 'YOUR CLIENT ID FROM GOOGLE DEVELOPER CONSOLE';
client_secret = 'YOUR CLIENT SECRET FROM GOOGLE DEVELOPER CONSOLE';
url = 'https://accounts.google.com/o/oauth2/token';
redirect_uri = 'urn:ietf:wg:oauth:2.0:oob';
code = 'YOUR AUTHORIZATION CODE';
data = [...
'redirect_uri=', redirect_uri,...
'&client_id=', client_id,...
'&client_secret=', client_secret,...
'&grant_type=', 'authorization_code',...
'&code=', code];
response = webwrite(url,data);
access_token = response.access_token;
headerFields = {'Authorization', ['Bearer ', access_token]};
options = weboptions('HeaderFields', headerFields, 'ContentType','json');
1 Comment
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/264403-how-can-i-access-an-api-which-requires-oauth-2-0-authorization-such-as-google-apis#comment_337207
Direct link to this comment
https://uk.mathworks.com/matlabcentral/answers/264403-how-can-i-access-an-api-which-requires-oauth-2-0-authorization-such-as-google-apis#comment_337207
Sign in to comment.