facebook / facebook-ruby-business-sdk Goto Github PK
View Code? Open in Web Editor NEWAn SDK built to facilitate application development for Facebook Ads API using Ruby.
License: Other
An SDK built to facilitate application development for Facebook Ads API using Ruby.
License: Other
In create_custom_audience.rb add_users
should be add_user
.
I think https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/field_types/datetime.rb has some troubles. For once, it should refer to the global namespace object "::DateTime" instead of "DateTime", I guess this (at least) sometimes refers to FacebookAds::FieldTypes::DateTime
instead.
Also, DateTime does not exists in stock ruby since 2.0, and requires active_support.
In any case, all my troubles went away when I added active_support, and monkeypatched FacebookAds::FieldTypes::DateTime as follows:
class FacebookAds::FieldTypes::DateTime
def deserialize(value, session = nil)
case value
when String
::DateTime.strptime(value, "%FT%T%:z")
else
::Time.at(value).to_datetime
end
end
end
(Note: only needed reading from the API.)
0.3.3
Getting FacebookAds::ClientError: (#2) Service temporarily unavailable:
on every request, not seeing any services/outages on their website?
@app_id = ENV.fetch('FACEBOOK_ACCOUNT_ID')
@app_secret = ENV.fetch('FACEBOOK_APP_SECRET')
@access_token = fetch_token
puts @access_token
@ad_account = FacebookAds::AdAccount.get("act_#{@app_id}",
'name',
access_token: @access_token,
app_secret: @app_secret)
puts "Ad Account Name: #{@ad_account.name}"
fetch_token
Prints an auth token correctly, which implies that the Account ID and Secret are correct.
the @ad_account
call gets the error reported above
the Ad Account name to be printed
When we use the stats
edge in AdsPixel
(https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/ad_objects/ads_pixel.rb#L57
)
has_edge :stats do |edge|
edge.get 'AdsPixelStatsResult' do |api|
api.has_param :aggregation, { enum: -> { AdsPixelStatsResult::AGGREGATION }}
api.has_param :end_time, 'datetime'
api.has_param :event, 'string'
api.has_param :start_time, 'datetime'
end
end
It returns AdsPixelStatsResult
and returned timestamp
field(field :timestamp, 'datetime'
) is defined as datetime
When deserializing datetime (https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/field_types/datetime.rb#L29), it's expecting date time format like 2017-08-31T23:59:00-04:00
with time difference,
...
when String
DateTime.strptime(value, '%FT%T%:z')
...
but for this case, returned datetime value is like 2017-08-16T14:00:00
without time difference.
Calling FacebookAds::Ad.get(ad_id).leads.all
when there are more than limit
results causes infinite loop,
since response doesn't include pagination data.
Only solution seems to be to place large enough limit, but that is not very safe,
since API itself can limit the maximum number of results returned, which can again cause same infinite loop.
Using latest versions of gem and API, 0.3.2.5
and 3.2
.
When I use filtering to find out some campaigns with ids, it said that The parameter filtering[0][operator] is required
, but I confirm I have the operator params,the code is below:
ad_account.campaigns(filtering: [{"field":"id","operator":"EQUAL", "value":"23842979460490127"}]).all
how can I use the filtering correctly? Thank you very much!
and where can I find more documentation on this front
Hey, I cannot get from a campagin the amount spend.
I tryed many fields ( dayli_spend, spend, amount spend etc.. ) :
undefined method `amount_spent' for #FacebookAds::Campaign:0x007f8903ae49b0
Any ideas ?
Thanks :)
v0.3.3.3
ids_of_invalid_requests
field missing on CheckBatchRequestStatus
object
> resp = catalog.check_batch_request_status(handle: "...handle here...", load_ids_of_invalid_requests: true)
> resp.first.handle
=> "...handle here..."
> resp.first.ids_of_invalid_requests
Traceback (most recent call last):
1: from (irb):8
NoMethodError (undefined method `ids_of_invalid_requests' for #<FacebookAds::CheckBatchRequestStatus:0x0000...>)>
Exception thrown for method not being defined in v0.3.3.3
Being able to use v0.4.0.1 which has this method/field defined
Aside from filling out the issue template, my main concern is that facebookbusiness
gem has not published a new version since v0.3.3.4:
https://rubygems.org/gems/facebookbusiness
whereas Github releases have 4 more versions released since then:
v0.4.0.1
v0.4.0.0
v0.3.3.6
v0.3.3.5
https://github.com/facebook/facebook-ruby-business-sdk/releases
Is it possible that you can publish the missing releases to rubygems?
Fetching an adset like so:
FacebookAds::Adset.get(objectSourceId, session)
Throws the exception "uninitialized constant FacebookAds::Adset", this only happens with adsets, it works fine with campaigns and ads
Ruby 2.6.0
facebookbusiness gem from versions 0.3.3.3
to 0.4.0.1
In versions >0.3.3.2, FacebookAds::AdAccount.get("XXX").adsets
has lost the create method.
This example to create an AdSet does not work as a result: https://github.com/facebook/facebook-ruby-business-sdk/blob/master/examples/AdAccountAdSetsPostCreateAdSet.rb
Current traceback
$ gem uninstall facebookbusiness -s
$ gem install facebookbusiness -v 0.4.0.1
$ irb
2.6.0 :001 > require 'facebookbusiness'
=> true
2.6.0 :002 > act = FacebookAds::AdAccount.get("act_XXXXXXXXXXXXXXXX")
=> #<FacebookAds::AdAccount {:id=>"act_XXXXXXXXXXXXXXXX"}>
2.6.0 :003 > act.adsets.create({})
Traceback (most recent call last):
4: from /home/mtamdev/.rvm/rubies/ruby-2.6.0/bin/irb:23:in `<main>'
3: from /home/mtamdev/.rvm/rubies/ruby-2.6.0/bin/irb:23:in `load'
2: from /home/mtamdev/.rvm/rubies/ruby-2.6.0/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
1: from (irb):3
NoMethodError (undefined method `create' for #<#<Class:0x00007fffbc0d4e40>:0x00007fffbc3c51b8>)
Intended traceback
$ gem uninstall facebookbusiness -s
$ gem install facebookbusiness -v 0.3.3.2
$ irb
2.6.0 :001 > require 'facebookbusiness'
=> true
2.6.0 :002 > act = FacebookAds::AdAccount.get("act_XXXXXXXXXXXXXXXX")
=> #<FacebookAds::AdAccount {:id=>"act_XXXXXXXXXXXXXXXX"}>
2.6.0 :003 > act.adsets.create({})
Traceback (most recent call last):
9: from /home/mtamdev/.rvm/rubies/ruby-2.6.0/bin/irb:23:in `<main>'
8: from /home/mtamdev/.rvm/rubies/ruby-2.6.0/bin/irb:23:in `load'
7: from /home/mtamdev/.rvm/rubies/ruby-2.6.0/lib/ruby/gems/2.6.0/gems/irb-1.0.0/exe/irb:11:in `<top (required)>'
6: from (irb):3
5: from /home/mtamdev/.rvm/gems/[email protected]/gems/facebookbusiness-0.3.3.2/lib/facebook_ads/edge.rb:95:in `create'
4: from /home/mtamdev/.rvm/gems/[email protected]/gems/facebookbusiness-0.3.3.2/lib/facebook_ads/ad_object.rb:132:in `block (2 levels) in <class:AdObject>'
3: from /home/mtamdev/.rvm/gems/[email protected]/gems/facebookbusiness-0.3.3.2/lib/facebook_ads/api_request.rb:48:in `execute'
2: from /home/mtamdev/.rvm/gems/[email protected]/gems/facebookbusiness-0.3.3.2/lib/facebook_ads/api_request.rb:53:in `execute_now'
1: from /home/mtamdev/.rvm/gems/[email protected]/gems/facebookbusiness-0.3.3.2/lib/facebook_ads/api_request.rb:67:in `create_response'
FacebookAds::ClientError (Invalid parameter: Required Field Is Missing (fbtrace_id: A7woqYlpigEe5jPHM0rA_nw))
Please fix that error
ALL
api.has_param :fb:channel, 'string'
api.has_param :image:height, 'int' ....
in files
/lib/facebook_ads/ad_objects/user.rb
/lib/facebook_ads/ad_objects/group.rb
than
uninitialized constant FAMEAdCampaign
must be a FameAdCampaign
in /lib/facebook_ads/ad_objects/campaign.rb
thanks
This code:
def sdk_ad_account
@sdk_ad_account ||= FacebookAds::AdAccount.get(
"act_#{@account_id}",
'name',
sdk_session
)
end
Gives me this error:
NameError:
undefined method `destroy' for class `FacebookAds::AdsPixel'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/helpers/node_helpers.rb:76:in `block in included'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/helpers/node_helpers.rb:75:in `class_eval'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/helpers/node_helpers.rb:75:in `included'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/helpers/node_helpers.rb:39:in `include'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/helpers/node_helpers.rb:39:in `has_no_delete'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/ad_objects/ads_pixel.rb:89:in `<class:AdsPixel>'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/ad_objects/ads_pixel.rb:28:in `<module:FacebookAds>'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/ad_objects/ads_pixel.rb:21:in `<top (required)>'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/ad_objects/ad_account.rb:562:in `block (3 levels) in <class:AdAccount>'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/field_types/enum.rb:25:in `initialize'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/field_types.rb:39:in `new'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/field_types.rb:39:in `for'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/param_set.rb:27:in `has_param'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/ad_objects/ad_account.rb:562:in `block (2 levels) in <class:AdAccount>'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/edge.rb:149:in `get'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/ad_objects/ad_account.rb:561:in `block in <class:AdAccount>'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/helpers/edge_helpers.rb:35:in `has_edge'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/ad_objects/ad_account.rb:560:in `<class:AdAccount>'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/ad_objects/ad_account.rb:28:in `<module:FacebookAds>'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4/lib/facebook_ads/ad_objects/ad_account.rb:21:in `<top (required)>'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `block in require'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:258:in `load_dependency'
# /Users/alex/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/activesupport-5.1.4/lib/active_support/dependencies.rb:292:in `require'
# ./lib/facebook/client.rb:22:in `sdk_ad_account'
This makes this gem unusable, basically.
removing users from custom audience is throwing error ''Data is missing or does not match schema:"
I am using
ca = FacebookAds::CustomAudience.get(<ad_account_id>, {
access_token: <Access_token>,
app_secret: <app_secret>
})
users = [['FirstName', '[email protected]', 'LastName1'],
['FirstNameTest', '[email protected]', 'LastNameTest']]
schema = ["FN","EMAIL","LN"]
ca.remove_user(users, schema)
When I execute above code I am getting error-- (#100) Data is missing or does not match schema:
The README has the following disclaimer:
We developed this SDK using Ruby 2.0, and supports Ruby 2.0+, however, the SDK is not thread-safe at the moment.
Is there a particular area of the SDK that isn't thread-safe that can be avoided? I see the with_session
method definitely isn't; can we avoid some elements to utilize the library in threaded background workers now?
If not, what can be done to improve thread safety? Is it a matter of prioritization? Allocation of resources? Lack of interest?
Thanks!
Hi! I am having issues making calls to the API using token for my main account. Things are working find when I push & fetch data using my sandbox credentials.
I am building a ROR app and trying to set start_time and end_time of an ad_set but it returns following exception.
FacebookAds::ClientError (Invalid parameter: Type Mismatch (fbtrace_id: HwzPJFp7o/8))
God knows how many formats i have tried.
following is my code
`ad_data["details"]["startDate"] = "2018-02-18T00:00:00"
ad_data["details"]["endDate"] = "2018-02-28T00:00:00"
from_date = DateTime.strptime(ad_data["details"]["startDate"], '%FT%T').to_time.utc.to_i
end_date = DateTime.strptime(ad_data["details"]["endDate"], '%FT%T').to_time.utc.to_i
puts from_date
adset = ad_account.adsets.create({
name: 'Test Ad Set',
campaign_id: campaign.id,
bid_amount: 10,
billing_event: 'LINK_CLICKS',
daily_budget: 150000,
from_time: from_date
})`
i have tried simple datetime string , DateTime Object, Time Object , Unix UTC etc.
I am new to ruby so excuse me if it's a code blunder.
[7] pry(main)> FacebookAds::VERSION
=> "0.3.2.9"
[11] pry(main)> RUBY_VERSION
=> "2.5.0"
Batch API has the logic to return the response.
However, there is no return value because each_slice has been added.
facebook-ruby-business-sdk/lib/facebook_ads/batch_api/batch.rb
Lines 33 to 51 in bd80d59
[4] pry(main)> require "facebookbusiness"
=> true
[5] pry(main)> session = FacebookAds::Session.new(access_token: access_token, app_secret: app_secret)
[6] pry(main)> batch = FacebookAds::Batch.with_batch do
FacebookAds::AdAccount.get("act_#{ad_account_id}", session).name
[6] pry(main)* end
[7] pry(main)> batch.execute
=> nil
Enumerable#each_slice
return nil.
https://ruby-doc.org/core-2.5.0/Enumerable.html#method-i-each_slice
I added the map
method.
It will be the expected result.
File: vendor/bundle/ruby/2.5.0/gems/facebookbusiness-0.3.2.9/lib/facebook_ads/batch_api/batch.rb
- 35: operations.each_slice(50) do |slice|
+ 35: operations.each_slice(50).map do |slice|
[6] pry(main)> batch.execute
=> [[#<FacebookAds::AdAccount {:id=>"act_****", :account_id=>"****"}>]]
When I request delivery_estimate
from edges of ad_account
, it raised TypeError
. estimate_dau
and estimate_mau
in Ad Account Delivery Estimate
defined as object
like below, but both fields returned as integer
from API.
https://github.com/facebook/facebook-ruby-ads-sdk/blob/b704d31bb0a94596078e05cb08fbe4d17732c7d1/lib/facebook_ads/ad_objects/ad_account_delivery_estimate.rb#L54
https://github.com/facebook/facebook-ruby-ads-sdk/blob/b704d31bb0a94596078e05cb08fbe4d17732c7d1/lib/facebook_ads/ad_objects/ad_account_delivery_estimate.rb#L55
Other types (like string_type
or list
) has several ways to handling if inputted different type of value what you expected are inputted. but object
type is not, it's always trying parse JSON
. bid_estimate
defined as object
, and it occurred TypeError
too. because bid_estimate
already has Hash at this point, not JSON string.
I tried like below...
ad_account = FacebookAds::AdAccount.get(<AD_ACCOUNT_ID>, <SESSION>)
ad_account.delivery_estimate(<REQUIRED_PARAMS>).first
# TypeError: no implicit conversion of Hash into String
# from /Users/san/.rvm/gems/ruby-2.3.4/gems/json-1.8.6/lib/json/common.rb:155:in `initialize'
Is there anywhere I can get full documentation to the functionality of this gem?
Hi,
I am creating a FB Custom Audience. It works fine but if I go to the FB Ad Manager and open the Audience and try to edit it. I get an error saying that the audience was created via the API and it can not show the details. I have attached my code and the error.
This seems like its so fundamental and googling for it results in no results for me, that I think something must be wrong. Is it possible to make a custom audience via an API and then edit OR even just view the rule details via FB Ads Manager
rule = {"inclusions":
{"operator":"or",
"rules": [
{"event_sources":[
{"type":"pixel","id": pixel_id}
],
"retention_seconds":2592000,
"filter":{
"operator":"and",
"filters":[
{"operator":"or",
"filters":[
{"field":"url",
"operator":"i_contains",
"value":"lifting"
},
{"field":"url",
"operator":"i_contains",
"value":"Crossfit"
}
]
}]
},"template":"VISITORS_BY_URL"}]
}
}
audience = @ad_account.customaudiences.create({ name: "Test Audience",
prefill: true,
rule: rule})
The error message from Facebook Ads Manager when I open the custom audience and try to edit it:
This rule was created through API or third party applications. It contains syntax that we currently don't support in our interface.
I am trying to figure out how to create a new AdAccount. Trying to follow the logic in the curl post from your FB docs here:
https://developers.facebook.com/docs/marketing-api/reference/ad-account
I've found issue in https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/ad_object.rb#L48 when using insights creation api.
def initialize(attributes, *args)
...
self.fields = fields + attributes.keys
...
end
above self.fields
is usually calling def fields=(fields)
below when there are no field: fields
declared.
https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/ad_object.rb#L96
But there is one place field: fields
declared found below
so when it goes to
self.fields = fields + attributes.keys
it tries to access below method with name=fields
instead of calling instance method fields=
def define_writer(name)
define_method("#{name}=") do |val|
changes[name] = val
@fields.add(name.to_s)
end
end
FacebookAds::AdAccount.get('act_xxxxxx').insights(fields: 'ad_report_run').create(level: 'ad', fields: ['ad_id'])
This will throw exception
NoMethodError: undefined method `add' for nil:NilClass
Just rename instance method def fields=(fields)
to either def _fields=(fields)
or more explicitly def response_fields=(fields)
Hello,
I am using facebookbusiness-0.4.0.1
and when I try to get all actions for one account, I receive the next error.
Traceback (most recent call last):
4: from fb_ads.rb:49:in <main>' 3: from /usr/local/rvm/gems/ruby-2.5.1/gems/facebookbusiness-0.4.0.1/lib/facebook_ads/edge.rb:46:in
each'
2: from fb_ads.rb:54:in block in <main>' 1: from /usr/local/rvm/gems/ruby-2.5.1/gems/facebookbusiness-0.4.0.1/lib/facebook_ads/fields.rb:48:in
block in define_reader'
/usr/local/rvm/gems/ruby-2.5.1/gems/facebookbusiness-0.4.0.1/lib/facebook_ads/helpers/node_helpers.rb:46:in `load!': load! is not supported for this object (RuntimeError)
This is my code:
ad_account = FacebookAds::AdAccount.get('act_some_account_id')
ad_account.insights(fields: 'cpc,clicks,cost_per_conversion,ctr,impressions,reach,spend,actions',
time_range: "{'since':'2019-06-01','until':'2019-06-30'}",
).each do |insights|
ap insights.actions
end
but when I print only "insights",
I get:
{
:cpc => "177.813025",
:clicks => "9996",
:ctr => "2.209056",
:impressions => "452501",
:reach => "213311",
:spend => "1777419",
:actions => [
[ 0] {
:action_type => "onsite_conversion.messaging_first_reply",
:value => "1"
},
[ 1] {
:action_type => "onsite_conversion.messaging_conversation_started_7d",
:value => "1"
},
.
.
.....
}
there is some wrong with my code?
thanks you,
I am getting this error, "Invalid parameter: Ambiguous Promoted Object Fields", when I try to create my ad. I have followed the code in the example you have provided. Here is my code for reference:
#Create ad campaign
campaign = ad_account.campaigns.create({
name: params[:campaign_name],
objective: 'LINK_CLICKS'
})
#Create adsets
ad_set = ad_account.adsets.create({
name: 'Test ad set' ,
campaign_id: campaign.id,
bid_amount: 1000,
billing_event: 'LINK_CLICKS',
daily_budget: 15000, #params[:daily_budget],
targeting: {
age_max: params[:age_max],
age_min: params[:age_min],
geo_locations: {
countries: [
"US"
]
},
publisher_platforms: [
"facebook",
],
facebook_positions: [
"feed",
],
instagram_positions: [
"stream",
],
device_platforms: [
"mobile",
"desktop",
],
}
})
#Create ad
ad = ad_account.ads.create({
status: 'PAUSED',
name: 'Test ad set',
adset_id: ad_set.id,
creative: {
object_story_spec: {
page_id: page_id,
link_data: {
link: params[:link],
message: params[:link_title],
name: "Test",
attachment_style: "link",
call_to_action: {
type: params[:call_to_action]
}
}
},
title: 'Test title',
body: 'Test body',
object_url: params[:link],
image_file: '/images/vynil.jpg'
},
logo: '/images/vynil.jpg'
})
Thank you!
Hi, maybe I'm not getting something here but when I get delivery estimate for adset I cannot read the responses data
, almost all methods beside to_yaml
return
TypeError: no implicit conversion of Hash into String
. It seems to me like there is a bug in the gem.
get this error whenever trying to make a post request to upload image
ArgumentError: wrong number of arguments (given 3, expected 1..2)
from /Users/davidhu/.rvm/gems/ruby-2.3.0/gems/faraday-0.9.0/lib/faraday/response/logger.rb:7:in `initialize'
I am using faraday-0.9.0
in faraday 0.9.0
def initialize(app, logger = nil)
in faraday 0.9.2
def initialize(app, logger = nil, options = {})
This error is caused by Facebook SDK expecting the initialize method in logger.rb
to accept 1..3
arguments instead of 1..2
ad_id = XXXXXX
FacebookAds::Ad.get(ad_id).leads({
fields:{},
filtering: [{
field:'time_created',
operator:'GREATER_THAN',
value: '2018-12-12T12:00:00-0800'
}].to_json
}).each(&:inspect)
In my example when I run the code above I get all the leads instead of the ones that are created after 12/12/2018.
No matter what I tried it always returns the all leads. Not sure if I'm doing something wrong or filtering not working.
Found one issue when using FacebookAds::FieldTypes::DateTime
https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/field_types/datetime.rb
module FacebookAds
module FieldTypes
class DateTime < Base
def deserialize(value, session = nil)
....
when String
DateTime.strptime(value, '%FT%T%:z')
....
end
def serialize(value)
....
when String
DateTime.parse(value).to_time.to_i
....
end
end
...
when it calls either deserialize
or serialize
with string value, it's calling either DateTime.parse
or DateTime.strptime
but since current class name is same as DateTime
, it will try to find a method in current class not from native one.
we can update them to ::DateTime.strptime
and ::DateTime.parse
When handling errors with Facebook, best practice is to use the error codes since the descriptions can change.
Facebook lays out the error codes here to make it easier to handle:
https://developers.facebook.com/docs/marketing-api/error-reference/
It looks like the only things being returned are fb_message
, error_user_title
and fbtrace_id
according to this:
https://github.com/facebook/facebook-ruby-business-sdk/blob/55700ad0afee5fa4a8f521ad4615fcff54d2d6a9/lib/facebook_ads/errors.rb
It should return an error code for the message being returned
Is there any way to get this error code that belongs to the message?
AdImage
IDs seem to consist of the account ID and the image hash with a colon as separator.
This leads to URI::InvalidURIError
exceptions when trying to load the resource by its ID.
A minimum example:
image = FacebookAds::AdAccount.get('act_12345678').adimages.first
image.hash
# => "feb391c9e7045348b52ef2081ed22830"
image.reload! # everything except the ID is cleared
image.hash
#=> URI::InvalidURIError: bad URI(is not URI?): 12345678:feb391c9e7045348b52ef2081ed22830
Hi, I am trying to make a registration of a custom audience using "facebook-ruby-ads-sdk" (gem is below).
I am using the source below.
https://github.com/facebook/facebook-ruby-ads-sdk/blob/v0.2.11.0/lib/facebook_ads/ad_objects/helpers/custom_audience_helpers.rb
When I specify the schema "UID" and use the method "add_user",
"is_raw" parameter is set to "true" in the library, and request to the Marketing API got sent.
The UID is hashed based on Digest::SHA256.hexdigest(data) in the gem.
When data is hashed, which "is_raw" parameter is correct, "true" or "false" ?
I appreciate for your support.
There are two places using invalid field types (map<string, unsigned int>
) in https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/ad_objects/ad.rb#L104 and https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/ad_objects/ad_set.rb#L129
so it doesn't get found in https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/field_types.rb#L44 when data for the field returned, and it returns as string
i.e.)
so when it returns hash object { 'foo' => 'bar' }
, it will be returned as "{\"foo\" => \"bar\" }"
as a string
The gem in its current form is not compatible with frozen string literals as destructive methods like gsub!
are used.
Here is an example:
# frozen_string_literal: true
FacebookAds::AdAccount.get('act_12345', 'name)
#=> RuntimeError: can't modify frozen String
#=> from .../gems/facebookads-0.2.10.0/lib/facebook_ads/session.rb:39:in `gsub!'
Immutable string literals will be the default in ruby 3, so it might be a good idea to already stop using destructive string methods.
Edit: It gets better as of course things like the following won't work either, as the result is already immutable without any additional magic comment:
FacebookAds::AdAccount.get(ENV['FB_AD_ACCOUNT_ID'], 'name)
It's generally bad practice to mutate an input parameter like this.
Hi after browsing the source code it seems this gem does not yet support Chunked Uploads for videos. Can you confirm? Deciding if we need to write this ourselves or not.
https://developers.facebook.com/docs/marketing-api/advideo/v2.11 -> "Chunked Upload"
Thanks!
I have set up a sandbox account and cannot create an ad, even after successfully obtaining the creative, adset, etc.
Failures:
FacebookAdsClient (development only tests) creates an ad
Failure/Error:
@ad_account.ads.create({
adset_id: "120330000021336603",
tracking_specs: "146149006094052",
name: "Track this",
creative: { creative_id: "120330000018226903" }
})
JSON::GeneratorError:
only generation of JSON objects or arrays allowed
/usr/local/rvm/gems/ruby-2.3.3/gems/json-1.8.6/lib/json/common.rb:223:in generate' /usr/local/rvm/gems/ruby-2.3.3/gems/json-1.8.6/lib/json/common.rb:223:in
generate'
/usr/local/rvm/gems/ruby-2.3.3/gems/facebookads-0.2.11.0/lib/facebook_ads/field_types/object.rb:29:in serialize' /usr/local/rvm/gems/ruby-2.3.3/gems/facebookads-0.2.11.0/lib/facebook_ads/param_set.rb:51:in
block in to_params'
/usr/local/rvm/gems/ruby-2.3.3/gems/facebookads-0.2.11.0/lib/facebook_ads/param_set.rb:39:in each' /usr/local/rvm/gems/ruby-2.3.3/gems/facebookads-0.2.11.0/lib/facebook_ads/param_set.rb:39:in
map'
/usr/local/rvm/gems/ruby-2.3.3/gems/facebookads-0.2.11.0/lib/facebook_ads/param_set.rb:39:in to_params' /usr/local/rvm/gems/ruby-2.3.3/gems/facebookads-0.2.11.0/lib/facebook_ads/edge.rb:92:in
create'
./lib/facebook_ads_client.rb:74:in `create_ad'
The error I got from console is:
FacebookAds::ClientError: (#2654) The specified engagement rule is invalid: Invalid subrule, subrule should be a json object: (fbtrace_id: C8drVEH1UbS)
Code is:
ca = ad_acc.customaudiences.create({
name: "#{Rails.env}-PECA-#{tuition_center.id}",
subtype: 'ENGAGEMENT',
description: "#{tuition_center.name}'s page engagement custom audiences.",
rule: {
object_id: tuition_center.facebook_ad_page_id,
event_name: "page_engaged"
}.to_json
})
When creating a new AdAccount on business, end_advertiser should be provided in string format. However, it is defined as object
as you can see below:
This raises #<JSON::GeneratorError: only generation of JSON objects or arrays allowed> because lib/facebook_ads/field_types/object.rb
tries to generate JSON from a string.
@business = FacebookAds::Business.get("BUSINESS_ID", "name", MY_BUSINESS_MANAGER_ADMIN_ACCOUNT_SESSION)
@business.adaccount.create(name: "Test AdAccount", currency: "USD", end_advertiser: MY_APP_ID)
# JSON::GeneratorError: only generation of JSON objects or arrays allowed
# from /Users/premist/.gem/ruby/2.3.4/gems/json-1.8.6/lib/json/common.rb:223:in `generate'
tl;dr there are 2 problems, Batch
doesn't return a response with anything other than ids and the gem makes N requests for N attributes that are called on an object.
I'm creating many AdSets
with FacebookAds::Batch.with_batch
. When I do batch.execute
, I get back only ids:
[
#<FacebookAds::AdSet {:id=>\"some-id-1\"}>,
#<FacebookAds::AdSet {:id=>\"some-id-2\"}>,
#<FacebookAds::AdSet {:id=>\"some-id-3\"}>
]
I need to access its name
and status
(I want to double check that those were created correctly). When I do object.first.name
, it makes Request1:
Request GET https://graph.facebook.com/v3.0/some-id-1?access_token=my-access-token&appsecret_proof=secret-prood&fields=name
Calling object.first.status
, another request is made:
Request GET https://graph.facebook.com/v3.0/some-id-1?access_token=my-access-token&appsecret_proof=secret-prood&fields=status
The diff is the fields
at the end. That led me to just load those ids with ::FacebookAds::AdSet
I want to load those records, so I do the following for each id:
::FacebookAds::AdSet.get('some-id-1', 'name,status,campaign_id', session)
That works, except that in reality I'm creating 3,000 ad sets for N customers. Facebook simply won't accept that many requests in serial. I tried using FacebookAds::Batch.with_batch
to no avail.
id
?object.name
and have it request N attributes at once, instead of one call per attribute? This is very inconvenient.Thanks a lot.
Latest
When editing an AdSet that is fetched from Facebook, this works.
adset = FacebookAds::AdSet.get(id)
adset.name = 'This is a test value'
adset.save
But if you try updating something nests, such as the age_min
, it does not set the value.
adset = FacebookAds::AdSet.get(id)
adset.targeting.age_min = 20
adset.save
It should set the value and update the AdSet
Trying to create a scheduled job to fetch insights from customer ad accounts but I need to constantly check the 'X-FB-Ads-Insights-Throttle' header in order to make sure Facebook doesn't limit me.
How can I check this header when calling the insights calls using the library?
Are you planning to add values like Field
in the Python SDK?
It is the following value.
https://github.com/facebook/facebook-python-ads-sdk/blob/master/facebookads/adobjects/ad.py#L77
Ruby SDK also has a Field-like declaration, but it's hard to use because it is an array.
https://github.com/facebook/facebook-ruby-ads-sdk/blob/master/lib/facebook_ads/ad_objects/ad.rb#L29
No matter what I put in fields
I always get back image hash and url
I modified the example image_upload.rb file as follows:
images = ad_account.adimages.create({
logo1: File.open(File.expand_path("../logo1.jpg", __FILE__)),
logo2: File.open(File.expand_path("../logo2.png", __FILE__)),
fields: ['name','hash']
})
and the object I get back contains hash
and url
attributes.
#<FacebookAds::AdImage {:hash=>"XXXXXXXXXX", :url=>"https://scontent.xx.fbcdn.net/v/t45.1600-4/XXXXXXXXXX"}>
Is read after write supported for ad images?
v0.3.3.1
Graph API v3.3 Will No Longer Be Supported
Use any of the methods of the SDK and Facebook will throw this warning
Graph API should be upgraded to 4.0
I am fetching a preview like so:
FacebookAds::AdCreative.get(creativeId, session).previews(ad_format: adFormat)
Every single preview i fetch the URL comes like this:
"https://www.facebook.com/ads/api/preview_iframe.php...........&t=AQK0********XnH5"
Notice how the "t" param has a ";" instead of a "&"
This is causing the links to return "The parameter t is required"
There is new options to include life-time value of the customer in custom audience:
https://developers.facebook.com/docs/marketing-api/value-based-lookalike-audience-targeting/
but when I add LOOKALIKE_VALUE to the schema, it is not recognized and gem try to hash the value (method hash_sha256).
Do I use it wrong or the support for LOOKALIKE_VALUE need to be added to the gem?
Hello!
Looks like there is some code to autoload all of the classes in facebook_ads/ad_objects/*
. However, the class_name
var set at line #69 does not work for the FacebookAds::IDName
class because the capitalize transform matches IdName
instead. We solved it locally by requiring that file directly:
require 'facebook_ads/ad_objects/id_name'
But, without that require statement, anything that references IDName fails.
is there any way to use this method ?
https://developers.facebook.com/docs/marketing-api/targeting-search
Thanks
Hi,
Is it possible to get the edge's data within a single api call ?
For example, I'd like to retrieve the ads within campaigns from my ad_account.
The graphql query i'd like : act_XXX?fields=campaigns{name,ads{name}}
I'm able to retrieve the campaigns ad_account.campaigns(fields: [:name])
but I can't manage to get the ads.
How can we do such a query?
If you look at
you will see the example code throws an error: => #<FacebookAds::Page {:id=>"177231702648138"}>
2.2.3 :037 > locationss = page.locations({
2.2.3 :038 > fields: { 'location{latitude''longitude}''is_permanently_closed' },
2.2.3 :039 > limit: '30000',
2.2.3 :040 > })
SyntaxError: (irb):38: syntax error, unexpected '}', expecting =>
However, it appears that, perhaps, this code should be:
locationss = page.locations({
fields: [ 'location', 'is_permanently_closed' ],
limit: '30000'
})
It looks like the fields value should be an array, with the values separated by commas and there should be no comma after limit since it is the last key-value pair in the hash. It's difficult to determine how to handle the location{latitude''longitude}
part of the example as that also does not seem to be a valid syntax.
I'm not forking and attempting to fix this myself as I'm still trying to understand the correct syntax to make queries. For the record, back in May, I was able query the API successfully:
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"
However now, with 0.3.0.6 (the latest version I can actually seem to make work), the same queries throw errors:
2.2.3 :080 > page = FacebookAds::Page.get('125200950858892', ["about","username","name","impressum","verification_status"])
=> #<FacebookAds::Page {:id=>"125200950858892"}>
2.2.3 :081 > page.id
=> "125200950858892"
2.2.3 :082 > page.attributes
=> {:id=>"125200950858892"}
2.2.3 :083 > page = FacebookAds::Page.get('125200950858892', "about,username,name,impressum,verification_status")
=> #<FacebookAds::Page {:id=>"125200950858892"}>
2.2.3 :084 > page.last_api_response
=> nil
2.2.3 :085 > page.username
ArgumentError: wrong number of arguments (3 for 1..2)
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/response/logger.rb:7:in `initialize'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/middleware.rb:21:in `new'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/middleware.rb:21:in `new'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:48:in `build'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:162:in `block in to_app'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:162:in `each'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:162:in `inject'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:162:in `to_app'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:152:in `app'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/faraday-0.9.0/lib/faraday/connection.rb:140:in `get'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/facebookbusiness-0.3.0.6/lib/facebook_ads/session.rb:41:in `request'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/facebookbusiness-0.3.0.6/lib/facebook_ads/api_request.rb:52:in `execute_now'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/facebookbusiness-0.3.0.6/lib/facebook_ads/api_request.rb:48:in `execute'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/facebookbusiness-0.3.0.6/lib/facebook_ads/ad_object.rb:123:in `block (2 levels) in <class:AdObject>'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/facebookbusiness-0.3.0.6/lib/facebook_ads/ad_object.rb:105:in `load!'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/facebookbusiness-0.3.0.6/lib/facebook_ads/fields.rb:48:in `block in define_reader'
from (irb):85
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/railties-3.2.22.5/lib/rails/commands/console.rb:47:in `start'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/railties-3.2.22.5/lib/rails/commands/console.rb:8:in `start'
from /Users/chip/.rvm/gems/ruby-2.2.3/gems/railties-3.2.22.5/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'2.2.3 :086 >
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.