本文整理汇总了Python中facebook_business.api.FacebookAdsApi.get_default_api方法的典型用法代码示例。如果您正苦于以下问题:Python FacebookAdsApi.get_default_api方法的具体用法?Python FacebookAdsApi.get_default_api怎么用?Python FacebookAdsApi.get_default_api使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类facebook_business.api.FacebookAdsApi
的用法示例。
在下文中一共展示了FacebookAdsApi.get_default_api方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_by_ids
# 需要导入模块: from facebook_business.api import FacebookAdsApi [as 别名]
# 或者: from facebook_business.api.FacebookAdsApi import get_default_api [as 别名]
def get_by_ids(cls, ids, params=None, fields=None, api=None):
api = api or FacebookAdsApi.get_default_api()
params = dict(params or {})
cls._assign_fields_to_params(fields, params)
params['ids'] = ','.join(map(str, ids))
response = api.call(
'GET',
['/'],
params=params,
)
result = []
for fbid, data in response.json().items():
obj = cls(fbid, api=api)
obj._set_data(data)
result.append(obj)
return result
示例2: __init__
# 需要导入模块: from facebook_business.api import FacebookAdsApi [as 别名]
# 或者: from facebook_business.api.FacebookAdsApi import get_default_api [as 别名]
def __init__(self, fbid=None, parent_id=None, api=None):
"""Initializes a CRUD object.
Args:
fbid (optional): The id of the object ont the Graph.
parent_id (optional): The id of the object's parent.
api (optional): An api object which all calls will go through. If
an api object is not specified, api calls will revert to going
through the default api.
"""
super(AbstractCrudObject, self).__init__()
self._api = api or FacebookAdsApi.get_default_api()
self._changes = {}
if (parent_id is not None):
warning_message = "parent_id as a parameter of constructor is " \
"being deprecated."
logging.warning(warning_message)
self._parent_id = parent_id
self._data['id'] = fbid
self._include_summary = True
示例3: remote_create_from_zip
# 需要导入模块: from facebook_business.api import FacebookAdsApi [as 别名]
# 或者: from facebook_business.api.FacebookAdsApi import get_default_api [as 别名]
def remote_create_from_zip(cls, filename, parent_id, api=None):
api = api or FacebookAdsApi.get_default_api()
open_file = open(filename, 'rb')
response = api.call(
'POST',
(parent_id, cls.get_endpoint()),
files={filename: open_file},
)
open_file.close()
data = response.json()
objs = []
for image_filename in data['images']:
image = cls(parent_id=parent_id)
image.update(data['images'][image_filename])
image[cls.Field.id] = '%s:%s' % (
parent_id[4:],
data['images'][image_filename][cls.Field.hash],
)
objs.append(image)
return objs
示例4: search
# 需要导入模块: from facebook_business.api import FacebookAdsApi [as 别名]
# 或者: from facebook_business.api.FacebookAdsApi import get_default_api [as 别名]
def search(cls, params=None, api=None):
api = api or FacebookAdsApi.get_default_api()
if not api:
raise FacebookBadObjectError(
"An Api instance must be provided as an argument or set as "
"the default Api in FacebookAdsApi.",
)
params = {} if not params else params.copy()
response = api.call(
FacebookAdsApi.HTTP_METHOD_GET,
"/".join((
FacebookSession.GRAPH,
FacebookAdsApi.API_VERSION,
'search'
)),
params,
).json()
ret_val = []
if response:
keys = response['data']
# The response object can be either a dictionary of dictionaries
# or a dictionary of lists.
if isinstance(keys, list):
for item in keys:
search_obj = TargetingSearch()
search_obj.update(item)
ret_val.append(search_obj)
elif isinstance(keys, dict):
for item in keys:
search_obj = TargetingSearch()
search_obj.update(keys[item])
if keys[item]:
ret_val.append(search_obj)
return ret_val