[Python] How can i get start date of particular ad in facebook_business lib in python

Discussão em 'Python' iniciado por Stack, Junho 6, 2025.

  1. Stack

    Stack Membro Participativo

    Below is my code implementation which i have did

    #Basic import from the facebook_business library
    from facebook_business.api import FacebookAdsApi
    from facebook_business.adobjects.adaccount import AdAccount
    from facebook_business.adobjects.adsinsights import AdsInsights
    from facebook_business.adobjects.adset import AdSet
    from facebook_business.adobjects.adreportrun import AdReportRun
    from facebook_business.exceptions import FacebookRequestError
    from facebook_business.adobjects.ad import Ad


    #code where im getting accesing the account
    FacebookAdsApi.init(eachAcc["BMAppID"], eachAcc["BMAppSecretKey"], eachAcc["BMToken"])
    FBTempDf = pd.DataFrame()
    try:
    ad_account = AdAccount(f'act_{eachAcc["FBaccountId"]}')
    #few things which im currently getting
    fields = [
    AdsInsights.Field.campaign_name,
    AdsInsights.Field.campaign_id,
    AdsInsights.Field.account_name,
    AdsInsights.Field.account_id,
    AdsInsights.Field.adset_name,
    AdsInsights.Field.adset_id,
    AdsInsights.Field.ad_name,
    AdsInsights.Field.ad_id,
    AdsInsights.Field.spend,
    AdsInsights.Field.inline_link_clicks,
    AdsInsights.Field.impressions,
    AdsInsights.Field.cpm,
    ]
    params = {
    'level': 'ad',
    'time_range': {'since':CurrentDate, 'until': CurrentDate},
    }
    insights = ad_account.get_insights(fields=fields, params=params)

    for insight in insights:
    ad_id = insight[AdsInsights.Field.ad_id]
    ad_name = insight[AdsInsights.Field.ad_name]
    spend_today = insight[AdsInsights.Field.spend]

    ad = Ad(ad_id)

    all_ads = ad_account.get_ads(fields=[
    Ad.Field.id,
    Ad.Field.name,
    Ad.Field.created_time,
    Ad.Field.start_time,
    Ad.Field.stop_time,

    ])

    **#above i have added start_time & stop_time but it's**



    Iam trying to find out when the ad actually started running, not just when it was created in the system The creation date only tells you when the ad was made, but you're looking for the start time of its live campaign or delivery. This is important because an ad can be created earlier but scheduled to run at a later date.

    Currently

    Continue reading...

Compartilhe esta Página