当前位置: 首页>>代码示例>>Python>>正文


Python api.FacebookAdsApi类代码示例

本文整理汇总了Python中facebook_business.api.FacebookAdsApi的典型用法代码示例。如果您正苦于以下问题:Python FacebookAdsApi类的具体用法?Python FacebookAdsApi怎么用?Python FacebookAdsApi使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了FacebookAdsApi类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, clientid, appsecret, token):
     session = FacebookSession(
             clientid,
             appsecret,
             token
     )
     self.api = FacebookAdsApi(session)
     self.object_queue = queue.Queue()
     self.batch = self.api.new_batch()
开发者ID:flashwade03,项目名称:facebook-businessapi-controller,代码行数:9,代码来源:fb_api.py

示例2: get_by_ids

 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
开发者ID:marcosptf,项目名称:fedora,代码行数:16,代码来源:abstractcrudobject.py

示例3: __init__

    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
开发者ID:marcosptf,项目名称:fedora,代码行数:20,代码来源:abstractcrudobject.py

示例4: remote_create_from_zip

    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
开发者ID:facebook,项目名称:facebook-python-ads-sdk,代码行数:23,代码来源:adimagemixin.py

示例5: search

    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
开发者ID:Work4Labs,项目名称:facebook-python-ads-sdk,代码行数:36,代码来源:targetingsearch.py

示例6: AdAccount

# 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 facebook_business.adobjects.adaccount import AdAccount
from facebook_business.adobjects.campaign import Campaign
from facebook_business.api import FacebookAdsApi

access_token = '<ACCESS_TOKEN>'
app_secret = '<APP_SECRET>'
app_id = '<APP_ID>'
id = '<AD_ACCOUNT_ID>'
FacebookAdsApi.init(access_token=access_token)

fields = [
]
params = {
  'name': 'Video Views campaign',
  'objective': 'VIDEO_VIEWS',
  'status': 'PAUSED',
}
print AdAccount(id).create_campaign(
  fields=fields,
  params=params,
)
开发者ID:facebook,项目名称:facebook-python-ads-sdk,代码行数:31,代码来源:AdAccountCampaignsPostVideoViews.py

示例7: open

this_dir = os.path.dirname(__file__)
config_filename = os.path.join(this_dir, os.pardir, os.pardir, 'config.json')

import sys
sys.path.insert(1, os.path.join(this_dir, os.pardir, os.pardir))

config_file = open(config_filename)
config = json.load(config_file)
config_file.close()

from facebook_business.api import FacebookAdsApi
from facebook_business.objects import ProductCatalog, Product

FacebookAdsApi.init(
    config['app_id'],
    config['app_secret'],
    config['access_token'],
)

if __name__ == '__main__':
    catalog_id = '<INSERT_YOUR_CATALOG_ID_HERE>'
    catalog = ProductCatalog(catalog_id)
    fields = [
        Product.Field.id,
        Product.Field.name,
        Product.Field.price,
        Product.Field.url,
        Product.Field.availability
    ]
    """
        get products cost more than $99.99.
开发者ID:Work4Labs,项目名称:facebook-python-ads-sdk,代码行数:31,代码来源:dpa_search.py

示例8: get_parent_id

 def get_parent_id(self):
     """Returns the object's parent's id."""
     return self._parent_id or FacebookAdsApi.get_default_account_id()
开发者ID:marcosptf,项目名称:fedora,代码行数:3,代码来源:abstractcrudobject.py

示例9: open

repo_dir = os.path.join(this_dir, os.pardir)
sys.path.insert(1, repo_dir)

from facebook_business.objects import AdAccount, AsyncJob
from facebook_business.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'}, is_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
开发者ID:Work4Labs,项目名称:facebook-python-ads-sdk,代码行数:31,代码来源:async.py


注:本文中的facebook_business.api.FacebookAdsApi类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。