Ruby gem facebook_ads exception_with_response:400错误请求

时间:2019-01-18 19:21:48

标签: facebook facebook-graph-api rubygems

我正在尝试使用facebook_ads Ruby gem查询Facebook Marketing API见解。 https://github.com/tophatter/facebook-ruby-ads-sdk

我创建了一个应用,并在与公司相关的页面上具有编辑权限。

接下来,我在选择ads_management权限后由此page生成了一个用户访问令牌。

接下来,我按照此page上的说明获取了永久的页面访问令牌。

使用下面的代码,我收到此错误:

  

/var/lib/gems/2.3.0/gems/rest-client-/var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:223 :以exception_with_response': 400 Bad Request (RestClient::BadRequest) from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/abstract_response.rb:103:in返回!”       来自/var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:809:in process_result' from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:725:in中的“传输”       来自/usr/lib/ruby/2.3.0/net/http.rb:853:start' from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:715:in中的“传输”       从/var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:145:in execute' from /var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient/request.rb:52:in执行'       从/var/lib/gems/2.3.0/gems/rest-client-2.0.2/lib/restclient.rb:67:in get' from /var/lib/gems/2.3.0/gems/facebook_ads-0.6.6/lib/facebook_ads/base.rb:15:in中获取       来自/var/lib/gems/2.3.0/gems/facebook_ads-0.6.6/lib/facebook_ads/ad_account.rb:10:in'all'

我也用我的临时用户访问代码尝试了此代码,但是得到了相同的结果。

这是我的代码

#!/usr/bin/ruby

require 'facebook_ads'

MY_PAGE_PERMANENT_ACCESS_CODE = 'my access code'

APP_SECRET = 'my app secret'

FacebookAds.access_token = MY_PAGE_PERMANENT_ACCESS_CODE

FacebookAds.app_secret = APP_SECRET

accounts = FacebookAds::AdAccount.all

1 个答案:

答案 0 :(得分:0)

事实证明,我使用的页面永久访问令牌超出了API调用的范围。我需要使用我的临时用户访问代码。

  

E,[2019-01-19T00:08:49.366067#19868]错误-:GET / me / adaccounts   OAuthException / 100:(#100)尝试访问不存在的字段   节点类型(Page)上的(帐户数)RestClient :: BadRequest:400错误   请求

在宝石的撬动控制台中,我运行了以下命令来设置帐户变量:

pry(main)> account = FacebookAds::AdAccount.find('act_MY_ACCOUNT_ID')

我得到这个错误:

  

E,[2019-01-19T00:12:24.760545#20188]错误-:GET / me / adaccounts   OAuthException / 2635:(#2635)您正在调用的版本已弃用   Ads API。请更新至最新版本:v3.2。   RestClient :: BadRequest:400个错误请求

因此,我运行了以下命令:

pry(main)> FacebookAds.base_uri = 'https://graph.facebook.com/v3.2'
  

https://graph.facebook.com/v3.2

然后再次pry(main)> account = FacebookAds::AdAccount.find('act_MY_ACCOUNT_ID')

最后,我跑了

pry(main)> account.ad_insights

但是当我知道它不应该为空时,结果是一个空数组。我将跳过gem,使用Ruby net / http直接查询API。