Problems using the goo.gl API from google apps script

前端 未结 2 1385
滥情空心
滥情空心 2021-01-06 16:47

I\'m trying to query the goo.gl API from inside a Google Apps Script. The problem I\'m seeing is the following error message:

Request failed for https://www.         


        
2条回答
  •  清酒与你
    2021-01-06 16:53

    The following code works perfectly.

    function ShortenUrl(){
    var url = 'https://www.googleapis.com/urlshortener/v1/url';
    var apiKey = 'AIzBlNS-3HZdxKgwj-x30';
    url += '?key=' + apiKey;
    var payload = {"longUrl":"www.google.com"};
    
    var parameters = { method : 'post',
                    payload:JSON.stringify(payload),
                    contentType:'application/json',                    
                    muteHttpExceptions:true};
    
    var response = UrlFetchApp.fetch(url, parameters);
    Logger.log(response);
    }
    

提交回复
热议问题