def get_agencies(self): """Returns a list of businesses associated with the ads pixel""" response = self.get_api_assured().call( 'GET', (self.get_id_assured(), 'shared_agencies'), ).json() ret_val = [] if response: keys = response['data'] for item in keys: search_obj = Business() search_obj.update(item) ret_val.append(search_obj) return ret_val
def api_create(self, parent_id, fields=None, params=None, batch=None, pending=False): from facebookads.adobjects.business import Business return Business(api=self._api, fbid=parent_id).create_ad_study( fields, params, batch, pending)
def api_create(self, parent_id, fields=None, params=None, batch=None, pending=False): from facebookads.adobjects.business import Business return Business(api=self._api, fbid=parent_id).create_offline_conversion_data_set( fields, params, batch, pending)
# of this software is subject to the Facebook Developer Principles and # Policies [http://developers.facebook.com/policy/]. This copyright notice # shall be included in all copies or substantial portions of the software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 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.adobjects.business import Business from facebookads.adobjects.productcatalog import ProductCatalog from facebookads.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAdsApi.init(access_token=access_token) fields = [] params = { 'name': 'Test Flight Catalog', 'vertical': 'flights', } print Business(id).create_owned_product_catalog( fields=fields, params=params, )
config_file = open(config_filename) config = json.load(config_file) config_file.close() # Setup session and api objects session = FacebookSession( config['app_id'], config['app_secret'], config['access_token'], ) FacebookAdsApi.set_default_api(FacebookAdsApi(session)) if __name__ == '__main__': business = Business('1628260363868706') ad_accounts = list(business.get_owned_ad_accounts()) print ad_accounts # # create video object # video = AdVideo(parent_id=config['act_id']) # video_path = os.path.join( # os.path.dirname(__file__), # 'test.mov' # #'sample.mp4' # ) # # # set video fields # video[AdVideo.Field.filepath] = video_path
def _define_account(self): """ It takes account and business list or None (befault) and extract only relivant AdAccounts. Return list of AdAccount """ import time if self.account_ids and not self.business_ids: return { 'BusinessID': { 'Unknown': [ AdAccount('act_' + self._clean_account_id(_id)) for _id in self.account_ids ] } } elif not self.account_ids and not self.business_ids: me = User(fbid='me') return {'BusinessID': {'Unknown': me.get_ad_accounts()}} elif not self.account_ids and self.business_ids: business = [ Business(self._clean_account_id(_id)) for _id in self.business_ids ] result = {'BusinessID': {}} for _business in business: result['BusinessID'][_business['id']] = [] for _account in _business.get_owned_ad_accounts(): result['BusinessID'][_business['id']].append(_account) time.sleep(60) return result elif self.account_ids and self.business_ids: accounts_in_userlist = [ AdAccount('act_' + self._clean_account_id(_id)) for _id in self.account_ids ] business = [ Business(self._clean_account_id(_id)) for _id in self.business_ids ] result = {'BusinessID': {}} for _business in business: result['BusinessID'][_business['id']] = [] for _account in _business.get_owned_ad_accounts(): result['BusinessID'][_business['id']].append(_account) result['BusinessID'][_business['id']] = [ _account for _account in accounts_in_userlist if _account in result['BusinessID'][_business['id']] ] time.sleep(60) return result else: return None
from facebook_business.adobjects.adreportrun import AdReportRun # Import th csv writer and the date/time function import datetime import csv import time # Set the info to get connected to the API. Do NOT share this info my_app_id = '<Your app id>' my_app_secret = '<Your app secret>' my_access_token = '<user token>' # Start the connection to the facebook API FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token) # Create a business object for the business account business = Business('<Business Page Acoount Name>') # Get today's date for the filename, and the csv data today = datetime.datetime.now() todaydate = today.strftime('%m/%d/%Y') todaydatehyphen = todaydate.strftime('%m-%d-%Y') # Define the destination filename filename = todaydatehyphen + '_fb.csv' filelocation = "/home/VIGNESHWAR.I/" + filename # Get all ad accounts on the business account me = AdAccountUser(fbid='me') adAccounts = me.get_ad_accounts() #accounts = business.get_owned_ad_accounts(fields=[AdAccount.Field.id])
from facebookads.adobjects.campaign import Campaign from facebookads.adobjects.adset import AdSet from facebookads.adobjects.ad import Ad from facebookads.adobjects.adsinsights import AdsInsights from datetime import date my_app_id = 'INSERT_YOUR_APP_ID' my_app_secret = 'INSERT_YOUR_APP_SECRET' my_access_token = 'INSERT_YOUR_ACESS_TOKEN' print("my_app_id:", my_app_id) print("my_app_secret:", my_app_secret) print("my_access_token:", my_access_token) FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token) my_business = Business(fbid='INSERT_YOUR_BUSINESS_MANAGER_ID') print("my_business:", my_business) my_accounts = list(my_business.get_assigned_ad_accounts()) print("All accounts:", list(my_business.get_assigned_ad_accounts())) my_account = my_accounts[0] print("my_account:", my_account) fields = [ AdsInsights.Field.campaign_name, AdsInsights.Field.cpc, AdsInsights.Field.cpm, AdsInsights.Field.ctr, AdsInsights.Field.impressions, AdsInsights.Field.frequency,
import getpass user = getpass.getuser() path = '/Users/' + user + '/Desktop/' print('Selected path for your my_facebook_access.py:', path) # Import my_facebook_access.py file, located on your Desktop, # where you have to store your Facebook private information (see README.md): import sys sys.path.append(path) from my_facebook_access import my_app_id, my_app_secret, my_access_token, my_business_id, campaigns_group # print("my_app_id:", my_app_id) # print("my_app_secret:", my_app_secret) # print("my_access_token:", my_access_token) FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token) my_business = Business(fbid=my_business_id) # print("my_business:", my_business) my_accounts = list(my_business.get_assigned_ad_accounts()) # print("All accounts:", my_accounts) selected_adaccount = my_accounts[1] # print("Selected Ad Account:", selected_adaccount) campaign_fields = [ Campaign.Field.id, Campaign.Field.name, Campaign.Field.objective, Campaign.Field.status ] # Import a list of Campaigns' Id. # Create your list by listing your Campaign Ids # in the campaigns_group var located in your my_facebook_access.py, # which should be located on your Desktop (see README.md).
# Policies [http://developers.facebook.com/policy/]. This copyright notice # shall be included in all copies or substantial portions of the software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # 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.adobjects.business import Business from facebookads.adobjects.offlineconversiondataset import OfflineConversionDataSet from facebookads.api import FacebookAdsApi access_token = '<ACCESS_TOKEN>' app_secret = '<APP_SECRET>' app_id = '<APP_ID>' id = '<ID>' FacebookAdsApi.init(access_token=access_token) fields = [] params = { 'name': 'offline_event_set', 'description': 'conversion data used for superbowl campaign', 'data_origin': 'DIRECTLY_FROM_PEOPLE', } print Business(id).create_offline_conversion_data_set( fields=fields, params=params, )
access_token = 'EAAMKqQl6f7IBAP8puZCc6oBYRA8pnw0Nump8rZBeaUgUzjVdubVZBRu6tV8w0KkO8ITIFzelgYBWt60ZCyGFjBMjvVvZBq35jgKUQOhW1VN2CI2Ist9hacjQzLRVGWXzwQ0qBjbjG9gJt5MMygOUStYR2pv1rpzVtMRDn2383SivS0c93PZAnNQlEhVGSfZAYnmQh3dkbzXaQZDZD' app_secret = 'cecf581c1e3916cb73d3ff0a2de74c53' ad_account_id = '3069537593134411' business_id = '699539507564745' page_id = '113744243668266' pixel_id = '266546624542113' app_id = '856146054905778' FacebookAdsApi.init(access_token=access_token) fields = [] params = { 'name': 'Test Catalog', } product_catalog = Business(business_id).create_owned_product_catalog( fields=fields, params=params, ) print 'product_catalog', product_catalog product_catalog_id = product_catalog.get_id() print 'product_catalog_id:', product_catalog_id, '\n' fields = [] params = { 'name': 'Test Feed', 'schedule': { 'interval': 'DAILY', 'url': 'https://developers.facebook.com/resources/dpa_product_catalog_sample_feed.csv', 'hour': '22' },