Has anyone call a web app written in Google App script from Server (Rails...).
The image below describes exactly my problem. When I call GAS project from Server, it always returns 302 status. But it's ok when I call GAS directly

I run this code alone (Ruby), response status was 200, but when I put this code into Rails project, Google App Script returned 302
require 'faraday'
spreasheet_url = 'xxx'
token = 'xxx'
conn = Faraday.new url: spreasheet_url
conn.authorization :Bearer, token
res = conn.post do |req|
req.headers['Content-Type'] = 'application/json'
req.body = data.to_json
end
p res.status
I have tried with Nodejs and Go and the same problem happened.
Please help me if you have any suggestions, thanks a lot!
For security reasons, content returned by the Content service isn’t served from script.google.com, but instead redirected to a one-time URL at script.googleusercontent.com. This means that if you use the Content service to return data to another application, you must ensure that the HTTP client is configured to follow redirects. For example, in the cURL command line utility, add the flag -L. Check the documentation for your HTTP client for more information on how to enable this behavior.
Content Service | Apps Script | Google Developers
If you use Ruby (with Faraday gem), the solution is you should add FollowRedirects middleware:
conn = Faraday.new(url: spreasheet_url) do |faraday|
faraday.use FaradayMiddleware::FollowRedirects
faraday.adapter Faraday.default_adapter
end
The idea same as Go or Nodejs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With