oauth - Doing an https POST request for token -


i trying following request in google apps script. request return token used accessing api.

post https://datamarket.accesscontrol.windows.net/v2/oauth2-13 content-type: application/x-www-form-urlencoded  client_id=users-client-id&client_secret=users-secret-key&grant_type=client_credentials&scope=http%3a%2f%2fapi.microsofttranslator.com%2f 

how do above request in google apps script. reading unable find solution. tried below, didn’t work. methods should use?

var oauthconfig = urlfetchapp.addoauthservice("bearer"); oauthconfig.setconsumerkey("users-client-id"); //some code omitted //i couldn't figure out put grant_type , scope  var result = urlfetchapp.fetch("http://api.microsofttranslator.com/v2/http.svc/translate?text=hello&from=en&to=ja",options); //gave oauth error 

addoauthservice meant oauth 1 services.

for oauth 2 you'll need manually post call. here example

var parameters = {     method : 'post',     payload : 'client_id='+client_id+'&client_secret='+client_secret+'&grant_type=authorization_code&redirect_uri='+redirect_url+'&code=' + code   };    var response = urlfetchapp.fetch(token_url,parameters).getcontenttext();  

you can see more formed example here - https://github.com/entaq/googleappsscript/blob/master/io2013/youtubeanalytics/oauth2.gs#l22


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -