Facebook FQL Query with Ruby

旧时模样 提交于 2019-12-02 02:39:46

The http call accepts a host, not a URL:

def http_get(domain,path,params)
    path = unless params.blank
        path + "?" + params.collect { |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.join('&')
      else
        path
    end
    request = Net::HTTP.get(domain, path)

end

def get_facebook_stats(url)

    params = {
        :query => 'SELECT total_count FROM link_stat WHERE url = "' + url + '"',
        :format => 'json'
    }

    http = http_get('api.facebook.com', '/method/fql.query', params)
    puts http

end

Please do not use camel case on method names on Ruby.

If you want to make HTTPS calls, you will have to use a different call:

require 'net/http'
require 'net/https'

http = Net::HTTP.new('somehost.com', 443)
http.use_ssl = true
path = '/login.html'

resp, data = http.get(path, nil)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!