本文整理汇总了Python中facebook_business.api.FacebookAdsApi.init方法的典型用法代码示例。如果您正苦于以下问题:Python FacebookAdsApi.init方法的具体用法?Python FacebookAdsApi.init怎么用?Python FacebookAdsApi.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类facebook_business.api.FacebookAdsApi
的用法示例。
在下文中一共展示了FacebookAdsApi.init方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: open
# 需要导入模块: from facebook_business.api import FacebookAdsApi [as 别名]
# 或者: from facebook_business.api.FacebookAdsApi import init [as 别名]
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.
示例2: AdAccount
# 需要导入模块: from facebook_business.api import FacebookAdsApi [as 别名]
# 或者: from facebook_business.api.FacebookAdsApi import init [as 别名]
# 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,
)
示例3: open
# 需要导入模块: from facebook_business.api import FacebookAdsApi [as 别名]
# 或者: from facebook_business.api.FacebookAdsApi import init [as 别名]
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