根据 Facebook 图形 API,我们可以使用此(示例)请求用户个人资料图片:
According to Facebook graph API we can request a user profile picture with this (example):
graph.facebook/1489686594/picture但是上一个链接的真实图片网址是:
But the real image URL of the previous link is:
profile.ak.fbcdn/hprofile-ak-snc4/hs356.snc4/41721_1489686594_527_q.jpg
如果您在浏览器上输入第一个链接,它会将您重定向到第二个链接.
If you type the first link on your browser, it will redirect you to the second link.
有没有办法通过 Ruby/Rails 获得完整的 URL(第二个链接),只知道第一个 URL?
Is there any way to get the full URL (second link) with Ruby/Rails, by only knowing the first URL?
(这是这个问题的重复,但对于Ruby)
(This is a repeat of this question, but for Ruby)
推荐答案您可以使用 Net::Http 并从响应中读取 Location: 标头
You can use Net::Http and read the Location: header from the response
require 'net/http' require 'uri' url = URI.parse('www.example/index.html') res = Net::HTTP.start(url.host, url.port) {|http| http.get('/index.html') } res['location']更多推荐
在 Ruby 中获取 URL 的重定向
发布评论