facebook / facebook-ruby-business-sdk

Ruby SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
208 stars 161 forks source link

undefined method `destroy' for class `FacebookAds::AdsPixel' on 0.3.1 up to 0.3.2.4 #59

Closed kurko closed 4 years ago

kurko commented 5 years ago

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.

kurko commented 5 years ago

I commented the problematic line,

  module NodeHasNoDelete
    def self.included(base)
      base.class_eval do
        #undef :destroy
      end
    end
  end

I started getting then

NameError:
       uninitialized constant FacebookAds::AdsPixel::SignalsIWLExtractor
     # /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:128:in `block (3 levels) 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/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/ads_pixel.rb:128:in `block (2 levels) 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/edge.rb:157:in `post'
     # /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:126:in `block 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/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/ads_pixel.rb:122: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/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)>'

Then I look for that class in the project

(5978) ~/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/facebookbusiness-0.3.2.4 (master)
→ ag SignalsIWLExtractor
------------------------------------------------------------------------
lib/facebook_ads/ad_objects/ads_pixel.rb
128:        api.has_param :event_type, { enum: -> { SignalsIWLExtractor::EVENT_TYPE }}
130:        api.has_param :extractor_type, { enum: -> { SignalsIWLExtractor::EXTRACTOR_TYPE }}

There's absolutely no mention of SignalsIWLExtractor definition in the codebase. Googling for that name shows me that the Python, PHP and Java projects have that class defined. I can only imagine that this gem is being auto-generated and no one is caring whether it's working or not.

Is anyone at Facebook really using this gem? Or is it just being auto generated without testing?

tvillafane commented 5 years ago

trying bumping to 0.3.2.5 manually, this is some autogenerated code that I tweaked and eventually got it to run:

` require 'facebook_ads'

access_token = '' ad_accountid = 'act' app_secret = '' page_id = '' app_id = '**'

FacebookAds.configure do |config| config.access_token = access_token config.app_secret = app_secret end

ad_account = FacebookAds::AdAccount.get(ad_account_id) campaign = ad_account.campaigns.create({ objective: 'PAGE_LIKES', status: 'PAUSED', buying_type: 'AUCTION', name: 'My Campaign', }) campaign_id = campaign.id print 'campaign_id:', campaign_id

ad_set = ad_account.adsets.create({ status: 'PAUSED', targeting: {'geo_locations':{'countries':['US']}}, daily_budget: '1000', billing_event: 'IMPRESSIONS', bid_amount: '20', campaign_id: campaign_id, optimization_goal: 'PAGE_LIKES', promoted_object: {'page_id': page_id}, name: 'My AdSet', }) ad_set_id = ad_set.id puts 'ad_set_id:', ad_set_id

creative = ad_account.adcreatives.create({ name: "hi name", object_story_spec: { page_id: page_id, link_data: { link: "https://www.example.com", message: "hi mom", name: "name", description: "desc", call_to_action: { type: 'LEARN_MORE' } } } })

creative_id = creative.id puts 'creative_id:', creative_id

ad = ad_account.ads.create({ status: 'PAUSED', adset_id: ad_set_id, name: 'My Ad', creative: {'creative_id':creative_id}, }) ad_id = ad.id print 'ad_id:', ad_id

ad = FacebookAds::Ad.get(ad_id) ad.previews({ ad_format: 'DESKTOP_FEED_STANDARD', })`

pretty embarrassing how much work I had to do to get this to run - but - those are the breaks

stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

kurko commented 4 years ago

Still waiting for an answer.

stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

kurko commented 4 years ago

Not fixed.

walt1020 commented 4 years ago

@kurko I don't think you are able to destroy AdsPixels through the adaccounts.adspixels edge. https://developers.facebook.com/docs/marketing-api/reference/ad-account/adspixels/.

Instead, assuming what you want to do is remove the pixel from being used by your ad account, you'll want to go in the opposite direction.

If you know the ID of the pixel you want to stop sharing with your ad account, you could possibly do something like

ads_pixel = FacebookAds::AdsPixel.get('YOUR PIXEL ID', YOUR SESSION WITH ACCESS TOKEN)

ad_account = FacebookAds::AdAccount.get('ID OF AD ACCOUNT YOU WANT TO STOP SHARING YOUR PIXEL WITH', YOUR SESSION WITH ACCESS TOKEN)

ads_pixel.shared_accounts.destroy({account_id: ad_account.account_id, business: 'YOUR BUSINESS ID'})

You do need to have the correct permissions to perform this action, however. Hope this helps.

kurko commented 4 years ago

@walt1020 not sure you read my description, but I'm not doing anything related to ad pixels. I'm instantiating an ad account and the code explodes with a stacktrace related to ad pixels.

walt1020 commented 4 years ago

@kurko hmm. Are you still using version 0.3.2.4? I've tried replicating your code (using my credentials, not sure if that has anything do with it, but I don't think it would), and it returns my FacebookAds::AdAccount object fine. I'm using version 0.3.3.3.

stale[bot] commented 4 years ago

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 4 years ago

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.