GithubHelp home page GithubHelp logo

Comments (5)

tony avatar tony commented on April 23, 2024

How can I make it so all fields come back? What about an exclude to do all fields except certain fields.

How is the behavior of get_default_read_fields supposed to work? Is there a chance it's not fully implemented at this point?

from facebook-python-business-sdk.

tony avatar tony commented on April 23, 2024

If you read this by email, I updated the code in my original example

from facebook-python-business-sdk.

archanl avatar archanl commented on April 23, 2024

Hi tony, thanks for asking and hope you get well soon.

There's no way currently to read all fields. You have to manually specify the fields relevant to you when reading. You can find out more information about the fields in the online Ads API documentation.

The get_default_read_fields class method simply returns the array of fields you may have specified using the set_default_read_fields class method.

In the first remote_read call, the sdk will call get_default_read_fields because it sees you haven't specified a fields parameter:

AdAccount.set_default_read_fields([x,y,z])
my_ad_account = AdAccount(fbid="{your account fbid}")
my_ad_account_object.remote_read()  # queries api to read fields x, y, and z
my_ad_account_object.remote_read(fields=[a, x]  # queries api to read field a and x

Iteration also respects the default fields:

AdSet.set_default_read_fields([e,f,g])
my_ad_campaign = AdCampaign(fbid="{campagin id}")
my_ad_sets = my_ad_campaign.get_ad_sets()  # when querying during iteration, will ask api to return ad set objects with the given fields e, f, and g

Does this resolve your issue?

P.S. I'm not sure what you're doing by specifying self.id or self in some places. I don't see any reference to self.

from facebook-python-business-sdk.

tony avatar tony commented on April 23, 2024

@archanl Thank you.

P.S. I'm not sure what you're doing by specifying self.id or self in some places. I don't see any reference to self.

Nevermind the self, it code was originally an instance method on my side changed for example in the issue.

There's no way currently to read all fields. You have to manually specify the fields relevant to you when reading. You can find out more information about the fields in the online Ads API documentation.

Totally, what about the python side of things? I want a list of all the field class properties in facebookads.objects.AdSet.Field, facebookads.objects.AdCampaign.Field, etc so I can put them into a list set_default_read_fields / fields would accept.

I'm trying to do something like it here:

[attr for attr in dir(fb_objects.AdCampaign.Field) if not callable(getattr(fb_objects.AdCampaign.Field, attr)) and not attr.startswith("__")].

The get_default_read_fields class method simply returns the array of fields you may have specified using the set_default_read_fields class method.

When using AdAccount.set_default_read_fields([x,y,z]), x is a class property like fb_objects.AdSet.Field.bid_info, or can it be bid_info?

P.S. Unless you are open to altering / expanding the behavior a bit / have anything to ad, this is a solved case for me as I just went with declaring the fields by hand. It did take me time to understand it, so maybe I can PR some doc updates.

from facebook-python-business-sdk.

archanl avatar archanl commented on April 23, 2024

When using AdAccount.set_default_read_fields([x,y,z]), x is a class property like fb_objects.AdSet.Field.bid_info, or can it be bid_info?

fb_objects.AdSet.Field.bid_info just evaluates to the string "bid_info". So x, y, and z can be either the full references to the string or hard coded strings if you don't care about code manageability.

P.S. Unless you are open to altering / expanding the behavior a bit / have anything to ad, this is a solved case for me as I just went with declaring the fields by hand. It did take me time to understand it, so maybe I can PR some doc updates.

Some work is indeed required regarding fields and field value enums. If you think you have a good solution to manage and retrieve fields well or can improve documentation, feel free to submit a pull request! One solution might be to use python 3 Enum module and its backport. Note that not all of an object's possible fields are always relevant when reading so it doesn't really make sense to read all fields. For example, an ad set may not have an end_date.

from facebook-python-business-sdk.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.