本文整理汇总了Python中facebookads.objects.AdAccount.get_insights方法的典型用法代码示例。如果您正苦于以下问题:Python AdAccount.get_insights方法的具体用法?Python AdAccount.get_insights怎么用?Python AdAccount.get_insights使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类facebookads.objects.AdAccount
的用法示例。
在下文中一共展示了AdAccount.get_insights方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_ads_insight
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_insights [as 别名]
def get_ads_insight(
self,
account_id,
):
"""
Pull insights from the Insight edge and return an array of
insight report
Params:
* `account_id` is fb AdAccount id
"""
ad_account = AdAccount(fbid = account_id)
insights = ad_account.get_insights()
return insights
示例2: open
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_insights [as 别名]
from facebookads.objects import AdAccount, AsyncJob
from facebookads.api import FacebookAdsApi
import time
import os
import json
this_dir = os.path.dirname(__file__)
config_filename = os.path.join(this_dir, 'config.json')
config_file = open(config_filename)
config = json.load(config_file)
config_file.close()
api = FacebookAdsApi.init(access_token=config['access_token'])
account_id = config['act_id']
account = AdAccount(account_id)
# Both Insights and Reportstats
i_async_job = account.get_insights(params={'level': 'ad'}, async=True)
# Insights
while True:
job = i_async_job.remote_read()
print("Percent done: " + str(job[AsyncJob.Field.async_percent_completion]))
time.sleep(1)
if job:
# print "Done!"
break
print(i_async_job.get_result())
示例3: AdAccount
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_insights [as 别名]
# 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 facebookads import test_config
ad_account_id = test_config.account_id
# _DOC open [ADACCOUNT_GET_INSIGHTS_FILTERING_BREAKDOWN]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, Insights
ad_account = AdAccount(ad_account_id)
params = {
'breakdowns': [
Insights.Breakdown.age,
Insights.Breakdown.gender
],
'filtering': [{
'field': 'campaign.name',
'operator': 'CONTAIN',
'value': '18-25'
}]
}
stats = ad_account.get_insights(params=params)
print(stats)
# _DOC close [ADACCOUNT_GET_INSIGHTS_FILTERING_BREAKDOWN]
示例4: AdAccount
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_insights [as 别名]
# 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 facebookads import test_config
ad_account_id = test_config.account_id
# _DOC open [ADACCOUNT_GET_INSIGHTS_DYNAMIC_PRODUCT_ADS]
# _DOC vars [ad_account_id:s]
from facebookads.objects import AdAccount, Insights
account = AdAccount(ad_account_id)
fields = [
Insights.Field.account_name,
Insights.Field.impressions,
Insights.Field.actions,
Insights.Field.product_id,
]
params = {
'date_preset': 'last_week',
'actions_group_by': ['action_type'],
}
stats = account.get_insights(fields=fields, params=params)
# _DOC close [ADACCOUNT_GET_INSIGHTS_DYNAMIC_PRODUCT_ADS]
示例5: deleteAdSetsInsight
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_insights [as 别名]
con = mdb.connect(db_host, db_username, db_password, db_name)
with con:
deleteAdSetsInsight(con, report_date)
for my_ad_account_id in my_ad_account_ids:
ad_account = AdAccount(my_ad_account_id)
fields = [
'campaign_group_name',
'campaign_name',
'campaign_id',
'impressions',
'clicks',
'spend',
'reach',
'actions',
'action_values'
]
params = {
'time_range': {
'since': report_date,
'until': report_date
},
'action_attribution_windows': ['28d_click'],
'breakdowns': ['impression_device', 'placement'],
'level': 'campaign',
'limit': 100000
}
ad_insights = ad_account.get_insights(fields, params)
for ad_insight in ad_insights:
writeAdInsight(ad_insight, con, report_date)
示例6: AdAccount
# 需要导入模块: from facebookads.objects import AdAccount [as 别名]
# 或者: from facebookads.objects.AdAccount import get_insights [as 别名]
account = AdAccount("act_596901567069013")
print account
### Get DataFrames
import numpy as np
import pandas as pd
since = raw_input("Since YYYY-MM-DD: ")
until = raw_input("Until YYYY-MM-DD: ")
##1. insights dataframe (key: adgroup_id)
fields = ["adgroup_id", "campaign_name", "impressions", "clicks", "spend"]
params = {"level": "adgroup", "time_range": {"since": since, "until": until}, "time_increment": 1}
# get iterator
insights = account.get_insights(params=params, fields=fields) # class 'facebookads.objects.EdgeIterator'
# into list
insights_list = list(insights)
# into DataFrame
insights_df = pd.DataFrame(insights_list)
# save as csv
insights_df.to_csv(until + "insights.csv", index=False, encoding="utf-8")
##2. creatives dataframe (key: creative_id)
c_fields = ["creative", "adgroup_id", "campaign_name"]
c_params = {"time_range": {"since": since, "until": until}, "time_increment": 1}
creatives = account.get_ad_groups(fields=c_fields, params=c_params)
# into list