任何人都可以从Server(Rails ...)调用用Google App脚本编写的网络应用。
下图准确描述了我的问题。当我从服务器调用GAS项目时,它总是返回302
状态。但是直接致电GAS没关系
我单独运行此代码(Ruby),响应状态为200
,但是当我将此代码放入Rails项目时,Google App脚本返回了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
我尝试使用Nodejs
和Go
时发生了相同的问题。
如果您有任何建议,请帮助我,非常感谢!
答案 0 :(得分:0)
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
如果您使用Ruby(带有Faraday gem),则解决方案是您应该添加FollowRedirects
中间件:
conn = Faraday.new(url: spreasheet_url) do |faraday|
faraday.use FaradayMiddleware::FollowRedirects
faraday.adapter Faraday.default_adapter
end
与Go
或Nodejs
相同的想法。