我正在尝试从我的facebook页面运行的广告中提取数据到csv并将其推送到sql db。我是Web开发的新手,我不确定是否必须创建一个单独的fb应用程序使用广告sdk来做这件事,或者如果我可以写一个脚本,或者我正朝着正确的方向前进。如果未设置api,则无法通过营销api的以下代码块导致Api调用#39;) facebookads.exceptions.FacebookBadObjectError:如果未设置api,则无法进行Api调用。 ,在与async_job的第一次api调用。任何链接/教程将不胜感激,因为我目前在文档
中丢失#!/usr/bin/env/python
import urllib2
import json
from facebookads.adobjects.campaign import Campaign
from facebookads.adobjects.adsinsights import AdsInsights
from facebookads.adobjects.adreportrun import AdReportRun
from facebookads.api import FacebookAdsApi
from facebookads import objects
import time
campaign = Campaign(xxxxxxxxx)
params = {
'level': AdsInsights.Level.campaign,
}
async_job = campaign.get_insights(params=params, async=True)
async_job.remote_read()
while async_job[AdReportRun.Field.async_percent_completion] < 100:
time.sleep(1)
async_job.remote_read()
time.sleep(1)
print(async_job.get_result())
答案 0 :(得分:2)
#!/usr/bin/env/python
import urllib2
import json
from facebookads.adobjects.campaign import Campaign
from facebookads.adobjects.adsinsights import AdsInsights
from facebookads.adobjects.adreportrun import AdReportRun
from facebookads.api import FacebookAdsApi
from facebookads import objects
import time
# init Facebook API
from facebookads.api import FacebookAdsApi
FacebookAdsApi.init(access_token='your_access_token')
campaign = Campaign(xxxxxxxxx)
params = {
'level': AdsInsights.Level.campaign,
}
async_job = campaign.get_insights(params=params, async=True)
async_job.remote_read()
while async_job[AdReportRun.Field.async_percent_completion] < 100:
time.sleep(1)
async_job.remote_read()
time.sleep(1)
print(async_job.get_result())
Facebook Doc令人困惑。