def get_adsets_under_campaign(self, fb_campaign_id, logger):
		""" read all adset under campaign"""
		total_adsets = []
		try:
			campaign = Campaign(str(fb_campaign_id))

			related_adsets_iterator = campaign.get_ad_sets(
				fields=[
					AdSet.Field.id,
					AdSet.Field.status,
					AdSet.Field.name,
					AdSet.Field.bid_amount,
					AdSet.Field.targeting,
				],
			)
			ADSET_BATCH_LIMIT = 25

			# Iterate over batches of active AdCampaign's
			count = 0
			for adsets in self.generate_batches(
				related_adsets_iterator,
				ADSET_BATCH_LIMIT,
			):
				api_batch = self.api.new_batch()
				total_adsets.extend(adsets)

				if len(total_adsets) >= 4 * ADSET_BATCH_LIMIT: # only fetch most 100 adsets
					break

			return total_adsets

		except Exception as e:
			logger.exception(e)
def get_adsets_under_campaign(campaign_id):
    campaign = Campaign(campaign_id)
    fields = [
        AdSet.Field.id,
        AdSet.Field.account_id,
        AdSet.Field.name,
    ]
    adsets = campaign.get_ad_sets(fields=fields)
    return adsets
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures

campaign_id = fixtures.create_campaign().get_id()

# _DOC oncall [pruno]
# _DOC open [ADCAMPAIGN_GET_ADSETS_ADS_MANAGEMENT_UI]
# _DOC vars [campaign_id]
from facebookads.objects import Campaign, AdSet

campaign = Campaign(campaign_id)
ads = campaign.get_ad_sets(
    fields=[
        AdSet.Field.name,
        AdSet.Field.start_time,
        AdSet.Field.end_time,
        AdSet.Field.daily_budget,
        AdSet.Field.lifetime_budget,
    ]
)
# _DOC close [ADCAMPAIGN_GET_ADSETS_ADS_MANAGEMENT_UI]
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# shall be included in all copies or substantial portions of the software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

from examples.docs import fixtures

campaign_id = fixtures.create_campaign().get_id()

# _DOC oncall [duliomatos]
# _DOC open [ADCAMPAIGN_GET_ADSETS]
# _DOC vars [campaign_id]
from facebookads.objects import Campaign, AdSet

campaign = Campaign(campaign_id)
fields = [
    AdSet.Field.name,
    AdSet.Field.configured_status,
    AdSet.Field.effective_status,
]
adsets = campaign.get_ad_sets(fields=fields)
for adset in adsets:
    print(adset[AdSet.Field.name])
# _DOC close [ADCAMPAIGN_GET_ADSETS]