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

Example code has incorrect syntax and won't parse #58

Closed csroberson closed 4 years ago

csroberson commented 5 years ago

If you look at https://github.com/facebook/facebook-ruby-business-sdk/blob/99ae0d54eb3d9626ed502f83626a398112953726/examples/PageNode.rb#L32 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 > 
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.