Hi Dash,
Is there a way to download the data when clicked on the submit button. I have written the code like below but don’t know why data is not downloading as we download from the platform and located in download folders.
@app.callback(Output('output_div-fb', 'children'),
[Input('submit-button', 'n_clicks')],
[State('ad_account_id', 'value'),
State('app_id', 'value'),
State('access_token', 'value'),
State('app_secret', 'value'),
State('metrics', 'value'),
State('breakdown', 'value'),
State('start-date', 'date'),
State('end-date', 'date'),
],
)
def facebook_output(clicks, ad_account_id, app_id, access_token, app_secret, metrics, breakdown,
start_date, end_date):
if clicks is not None:
my_ad_account = ad_account_id
my_app_id = app_id
my_access_token = access_token
my_app_secret = app_secret
my_metrics = metrics
my_breakdown = breakdown
my_start_date = start_date
my_end_date = end_date
my_action_type = 'action_type'
my_level = 'ad'
my_time_increment = 1
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token,
api_version='v5.0')
me = User(fbid="me")
new_col_list = my_metrics
# print(new_col_list)
act = AdAccount(my_ad_account)
async_job = act.get_insights(params={'time_range': {'since': my_start_date, 'until': my_end_date},
'breakdowns': list(my_breakdown),
'action_breakdowns': my_action_type, 'level': my_level,
'time_increment': my_time_increment},
fields=list(new_col_list))
df = pd.DataFrame(async_job)
dff = df[new_col_list]
html.Br()
report_name = 'facebook_{}.csv'.format(datetime.datetime.now().strftime("%Y_%m_%d-%H_%M_%S"))
csv_string = dff.to_csv(report_name, index=False, encoding='utf-8')
csv_string = "data:text/csv;charset=utf-8,%EF%BB%BF" + urllib.parse.quote(csv_string)
return csv_string