ruby
  • facebook
  • 2014-02-19 79 views 0 likes 
    0

    我試圖用Ruby一次性獲得多個URL的相同數量。我已經試過這樣的事情,但它似乎並沒有工作時:Facebook API批量喜歡請求

    batch_get = [{"method"=>"GET", "relative_url"=>"method/fql.query?query=select total_count from link_stat where url='http://www.bbc.co.uk/news/world-us-canada-26233909'"}, {"method"=>"GET", "relative_url"=>"method/fql.query?query=select total_count from link_stat where url='http://english.chosun.com/site/data/html_dir/2014/02/19/2014021900954.html'"}] 
    
    q = "select total_count from link_stat where url='#{batch_get}'" 
    fbreq = URI.escape("https://graph.facebook.com/?batch=#{q}") 
    JSON.parse(open(fbreq).read) 
    

    我能夠獲得單一的URL喜歡,但表現相當糟糕,我想,讓他們在一個請求。這是可行的嗎?

    感謝

    回答

    0

    你並不需要批量這一點,它可以通過一個單一的FQL查詢來完成:

    select url, total_count from link_stat where url in ('http://www.bbc.co.uk/news/world-us-canada-26233909','http://english.chosun.com/site/data/html_dir/2014/02/19/2014021900954.html') 
    

    因此,請求將被

    https://graph.facebook.com/fql?q=select+url%2C+total_count+from+link_stat+where+url+in+%28%27http%3A%2F%2Fwww.bbc.co.uk%2Fnews%2Fworld-us-canada-26233909%27%2C%27http%3A%2F%2Fenglish.chosun.com%2Fsite%2Fdata%2Fhtml_dir%2F2014%2F02%2F19%2F2014021900954.html%27%29&access_token=YOUR_ACCESS_TOKEN 
    
    +0

    完美地工作!感謝:D – DaniG2k

    +0

    請記住,FQL現在已被棄用的facebook api v2.1 + – ecdeveloper

    +0

    這是真的,但到寫作答案時,它不是。此外,如果您有v2.0應用程序,則可以在2016年8月7日之前使用FQL。 – Tobi

    相關問題