本文整理汇总了Python中facebookads.objects.AdAccount.get_ad_creatives方法的典型用法代码示例。如果您正苦于以下问题:Python AdAccount.get_ad_creatives方法的具体用法?Python AdAccount.get_ad_creatives怎么用?Python AdAccount.get_ad_creatives使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类facebookads.objects.AdAccount
的用法示例。
在下文中一共展示了AdAccount.get_ad_creatives方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AdAccount
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_ad_creatives [as 别名]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount
account = AdAccount(ad_account_id)
objects = account.get_connection_objects()
for obj in objects:
print(obj[AdAccount.Field.name])
# _DOC close [ADACCOUNT_GET_CONNECTION_OBJECTS]
# _DOC open [ADACCOUNT_GET_ADCREATIVES]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdCreative
ad_account = AdAccount(fbid=ad_account_id)
ad_account.get_ad_creatives(fields=[AdCreative.Field.object_story_id])
# _DOC close [ADACCOUNT_GET_ADCREATIVES]
# _DOC open [ADACCOUNT_GET_ADGROUPS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, AdGroup
ad_account = AdAccount(ad_account_id)
ad_groups = ad_account.get_ad_groups(fields=[AdGroup.Field.name])
for ad_group in ad_groups:
print(ad_group[AdGroup.Field.name])
# _DOC close [ADACCOUNT_GET_ADGROUPS]
# _DOC open [ADACCOUNT_GET_ADGROUPS_WITH_STATUS]
示例2: list
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_ad_creatives [as 别名]
# into list
creatives_list = list(creatives)
# into DataFrame
from pandas.io.json import json_normalize
creatives_df = json_normalize(creatives_list)
# rename
creatives_df.rename(columns={"creative.id": "creative_id", "id": "adgroup_id"}, inplace=True)
# save as csv
creatives_df.to_csv(until + "creatives.csv", index=False, encoding="utf-8")
# 3. links dataframe (key: creative_id)
l_fields = ["object_story_spec"]
# links = account.get_ad_creatives(params = c_params, fields=l_fields)
links = account.get_ad_creatives(fields=l_fields)
# into list
links_list = list(links)
# into DataFrame
# When using json_normalize, the first record should have all the fields, or column names
start = 0
for i in range(len(links_list)):
if len(links_list[i]) != 1:
start = i
break
links_df = json_normalize(links_list[start:])
# rename
links_df.rename(columns={"id": "creative_id", "object_story_spec.link_data.link": "link"}, inplace=True)
# SettingWithCompyWarning:
# a value is trying to be set on a compy of a slice from a DataFrame
# save as csv