Filtering statistics from facebook ads api using the python sdk -


To get data about ad accounts / campaigns / etc within a certain time frame, Facebook's advertising-API I am trying to use / P>

So far, I managed to get the overall information (added below) using official python SDK, but I did not know how to insert time filter status.

The answer is probably under "filtering outcome" here, but I do not understand what they are doing for dragon, to translate it ...

I really appreciate any help you provide,

Thank you!


This module related to the official Python SDK project (I think):

My current code is:

  facebookads.session import Import facebookads.api from FacebookSession from FacebookAdsApi to Facebookads facebookads.objects Import (AdUser, AdCampaign,) my_app_id = 'import_pic' my_app_secret = 'AP_SECRET' my_access_token = 'ACCESS_TOKEN' my_session = FacebookSession (my_app_id, My_app_secret, my_access_token) my_api = FacebookAdsApi (my_session) FacebookAdsApi.set_default_api (my_api) I = objects.AdUser (fbid = 'I') my_accounts = list (me.get_ad_accounts ()) my_account = my_accounts [1] print ( "& gt; & gt; & gt ; Campaign statistics ") my_account.get_ad_campaigns (fields = [ AdCampaign.Field.name]) for the campaign: campaign.get_stats (fields = [ 'impressions, clicks on the' cost ',' Unique_clicks', 'State' for actions)): State In print (campaign [campaign.Field.name]): print ("\ t% s: \ t \ t% s"% (Statefold, State [Statfield]))  
< p> and output I get (all caps and xxxx I):

  campaign statistics CAMPAIGN_NAME1 impressions: xxxx unique_clicks: xxxx click: xxxx action: {u'mobile_app_install ': xxxx, u' App_custom_event ': xxxx, u'app_custom_event.fb_mobile_activate_app': xxx} Spend: xxxx CAMPAIGN_NAME2 imprint Issues: xxxx unique_clicks: xxxx click: xxxx action: {XXXX} expenses: xxxx  

There is an additional parameter name in the parameter where you can pass start_time and / or end_time in the get_stats () method Are there.

  params_data = { 'start_time to state statistics: 1415134405,} stats = campaign.get_stats (params = params_data, fields = [' Impressions', 'Clicks', ...]) ...  

The API accepts several different parameters, recorded here:

More Alternate Readings

Due to both the parameter parameter and the field parameter requires a little bit of detail if you are not interested, then do not pay attention to it.

The implementation for the parameter parameter basically creates the query string for the API call:

  params ['start_time' ] = 1415134405  

creates:?

  start_time = 1415134405  

Ad API endpoints generally accept a fields

 ? Fields = Impressions, Clicks & amp; start_time = 1415134405  

that you have correctly defined parameter, but since it's just field in the query string , So you can also do this technically:

  consultation [field]] = 'impressions, clicks'  

get_stats () < Field parameters (and other read methods) in / code> are an easy way to define this field parameter. The implementation looks something like this:

  def remote_prode (self, parameters = [], field = []): ... parameter ['fields'] = field ...  

Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -