Facebook FQL Query with Ruby

前端 未结 1 544
梦谈多话
梦谈多话 2021-01-22 00:10

I\'m trying to do a simple GET with ruby to the Facebook fql.query method without success.

The url is basically structured like this:

https://api.faceboo         


        
相关标签:
1条回答
  • 2021-01-22 00:37

    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)
    
    0 讨论(0)
提交回复
热议问题