首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Facebook Business SDK检索页面的多个字段

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

Stack Overflow用户
提问于 2018-05-08 08:10:25
回答 1查看 237关注 0票数 0

Facebook最近宣布的变化(例如,4月24日和May 1, 2018)导致我们关注Facebook Business SDK,据我所知,它是Facebook Marketing/Facebook Ads API的后代。

Facebook在Github上指出了他们的各种宝石,但大多数例子都提到了管理广告和活动。例如facebook/facebook-ruby-business-sdk

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

代码语言:javascript
复制
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本身使得检索Page (节点)的多个字段变得非常容易,所以我不明白为什么新的SDK表面上看起来效率如此之低(或者至少文档很差)。

我想我遗漏了一些很明显的东西。有一个批处理API,但我假设它更适合于一次检索多个页面,而不是检索单个页面的多个字段。

我希望其他人已经发现了这一点。

谢谢。

PS:如果有人有名誉点,我认为这个帖子应该有facebook-business-sdkfacebook-ruby-business-sdk作为标签。

EN

回答 1

Stack Overflow用户

发布于 2018-05-08 11:31:35

好的,这是一个答案,但不一定是答案。我认为仍然需要一个更好的答案,但这是我们已经发现的。

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

代码语言:javascript
复制
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"}

如果有一种更直接的方法来检索属性,那就太好了,但这还没有公开。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50224045

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档