0

I'm building a simple spreadsheet that monitors a series of url for their social sharing data using the sharedcount.com API.

For some reason the UrlFetchApp.fetch() eliminate the url I pass as a parameter of the endpoint to interrogate.

This is my code:

var sheet = SpreadsheetApp.getActiveSheet(),
          urls = sheet.getRange('A:A').getValues().slice(1),
          apikey = "XXXXXXXXXXXXXXXXX",
          apiEndPoint = "https://free.sharedcount.com/"
          data = [];

      urls.forEach(function(url, idx) {

        apiurl = apiEndPoint + '?url=' + encodeURIComponent(url) + '&apikey=' + apikey

        Logger.log(apiurl)

        sharedCountData = UrlFetchApp.fetch(apiurl)
        data[idx] = sharedCountData
      })

The logger function returns the correctly built url (eg: https://free.sharedcount.com/?url=http%3A%2F%2Fwww.teamvaxitalia.it%2F&apikey=XXXXXXXXXXXXXX), but running my code I receive a 401 error when it reach fetch(), in which the passed endpoint is this: https://free.sharedcount.com/?url=&apikey=XXXXXXXXXXXXXX and the error is "Not a valid URL". The url parameter is missing!

Any idea about what's going on?

Thanks

SOLVED: For some reason with UrlFetchApp.fetch it was needed to use https://free.sharedcount.com/url?url= as endpoint, not just https://free.sharedcount.com/?url=, even if in browser both work.

0

1 Answer 1

1

SOLVED: For some reason with UrlFetchApp.fetch it was needed to use https://free.sharedcount.com/url?url= as endpoint, not just https://free.sharedcount.com/?url=, even if in browser both work.

But suggestions on why this was happening are welcome.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.