首页 文章

如何使用Facebook Business SDK检索页面的多个字段

提问于
浏览
0

Facebook最近公布的变化(例如4月24日和May 1, 2018)导致我们看到了Facebook Business SDK,据我所知,它是Facebook营销/ Facebook广告API的后代 .

Facebook在Github上指出了各自的宝石,但大多数示例都参考了管理广告和广告系列 . 例如facebook/facebook-ruby-business-sdk .

使用他们在Facebook's Getting Started页面上的test.rb示例,我能够拼凑出以下测试 . 正如您在下面看到的,看起来每个检索字段值的方法调用似乎都会导致单独的API调用(或至少某种形式的网络访问):

1 > FacebookAds.configure do |config|
2 >       config.access_token = '<deleted>'
3?>     config.app_secret = '<deleted>'
4?>   end
 => #<FacebookAds::Config:0x007fd1f453ade0 @access_token="<deleted>", @app_secret="<deleted>"> 

5 >   page = FacebookAds::Page.get('125200950858892', "about,fan_count,impressum,username")
 => #<FacebookAds::Page {:id=>"125200950858892"}> 

6 > page.__all_fields
 => #<Set: {:about, :fan_count, :impressum, :username, :id}> 

7 > page.about
 => "Brandle® delivers social media security & brand protection.  It's the easiest way to Discover, Inventory, Monitor & Patrol your social presence!" 

# Turn wifi off

8 >   page.username
Faraday::ConnectionFailed: getaddrinfo: nodename nor servname provided, or not known

# Turn wifi on

9 >   page.username
 => "BrandleSystem"

Graph API本身使得为页面(节点)检索多个字段变得非常容易,因此我不明白为什么新SDK看起来效率低下(或至少记录不清楚) .

我想我错过了一些相当明显的东西 . 有一个批处理API,但我认为这更多的是一次检索多个页面,而不是检索单个页面的多个字段 .

我希望其他人已经弄明白这一点 .

谢谢 .

PS:如果有人有我没有的声望点,我认为这个帖子应该有 facebook-business-sdkfacebook-ruby-business-sdk 作为标签 .

1 回答

  • 0

    好的,这是一个答案,但不是必要的答案 . 我认为仍然需要更好的答案,但这是我们所看到的 .

    每次调用返回单个字段的方法之一时,都会调用API . 您可以从 page.last_api_response.headers["date"] 返回的值中看到 . 但是,一旦检索到第一个字段,所有字段都可用,并且可以通过调用 page.attributespage.to_hash 来检索 .

    006 >   page = FacebookAds::Page.get('125200950858892', "about,username,name,impressum,verification_status")
     => #<FacebookAds::Page {:id=>"125200950858892"}> 
    007 > page.last_api_response
     => nil 
    008 > page.attributes
     => {:id=>"125200950858892"} 
    
    010 >   page.username
     => "BrandleSystem" 
    012 > page.attributes
     => {:id=>"125200950858892", :about=>"Brandle® delivers social media security & brand protection.  It's the easiest way to Discover, Inventory, Monitor & Patrol your social presence!", :username=>"BrandleSystem", :name=>"Brandle", :verification_status=>"not_verified"} 
    013 > page.last_api_response.headers["date"]
     => "Tue, 08 May 2018 03:19:12 GMT" 
    
    015 >   page.name
     => "Brandle" 
    017 > page.attributes
     => {:id=>"125200950858892", :about=>"Brandle® delivers social media security & brand protection.  It's the easiest way to Discover, Inventory, Monitor & Patrol your social presence!", :username=>"BrandleSystem", :name=>"Brandle", :verification_status=>"not_verified"} 
    018 > page.last_api_response.headers["date"]
     => "Tue, 08 May 2018 03:20:02 GMT" 
    
    020 >   page.to_hash
    

    => {:id =>“125200950858892”,:about =>“Brandle®提供社交媒体安全和品牌保护 . 这是发现,盘点,监控和巡视您的社交存在的最简单方法!”,:username =>“BrandleSystem “,:name =>”Brandle“,:verification_status =>”not_verified“}

    如果有更直接的方法来检索属性,但尚未曝光,那将是很好的 .

相关问题