2016-04-07 16 views
0

毎日広告レポートにログインしてエクスポートする必要があります。どうすれば自動化できますか?Facebookのパワーエディタでスクリプトのエクスポートレポートを自動化するにはどうすればよいですか?

毎朝コンピュータにレポートのcsvをダウンロードしてもらいたいです。

カールを使用できますか? APIを使用するにはがありますか?これにはどのようなオプションがありますか?

Facebookはレポートの電子メール送信をスケジュールすることができますが、実際にレポートを電子メールで送信するのではなく、レポートへのリンクを電子メールで送信します。

編集

はまだこれをテストすることができていないが、それはthis guy used to be able to use wget to pull a reportのように見える(しかし、今では動作しません):私はアプリケーションIDを作成する前に、カール でこれをやろうとしています私はちょうどグラフアプリから生成されたユーザートークンでこれを行うにしようとしていますし、それが動作しているように表示されません。

curl 'https://www.facebook.com/ads/ads_insights/export_report?MYREPORTNAME&format=csv&access_token=MYACCESSTOKEN' 

私はレポートをダウンロードするためにカール使うのですか、カールを使用してドキュメントの例で見ます?

+1

はいAPIを使用する必要があります – WizKid

+0

APIを使用するには、開発者アカウントを作成する必要があり、Webサーバーで実行するアプリケーションを作成する必要があると言います。私はちょうどアプリケーションを書かないレポートをダウンロードしたい。 – red888

+0

誰かがあなたがそれをダウンロードしているということを認証する必要があります。それはアプリを使用して行われます。 – WizKid

答えて

1

を、私はレポートを自動化しようとするFBのAPIで働いている...のpythonと

まず、私は必要フィールドを持つレポート、コード生成:

from facebookads.api import FacebookAdsApi 
from facebookads.adobjects.adset import AdSet 
from facebookads.adobjects.campaign import Campaign 
from facebookads.adobjects.adsinsights import AdsInsights 
from facebookads.adobjects.adreportrun import AdReportRun 
import time 

my_app_id = 'your_app_id' 
my_app_secret = 'your_app_secret' 
my_access_token = 'you_access_token' 

FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token) 
campaign = Campaign(your_campaig_id) 
campaign.remote_read(fields=[ 
    Campaign.Field.effective_status 
]) 

params = { 
    'level': AdsInsights.Level.ad, 
    'fields': [ 
     AdsInsights.Field.account_name, 
     AdsInsights.Field.account_id, 
     AdsInsights.Field.campaign_name, 
     AdsInsights.Field.campaign_id, 
     AdsInsights.Field.impressions, 
     AdsInsights.Field.spend, 
     AdsInsights.Field.unique_clicks, 
     AdsInsights.Field.unique_inline_link_clicks, 
     AdsInsights.Field.total_actions, 
     AdsInsights.Field.total_unique_actions, 
     AdsInsights.Field.unique_actions, 
     AdsInsights.Field.ad_name, 
     AdsInsights.Field.ad_id, 
     AdsInsights.Field.reach, 
     AdsInsights.Field.video_p100_watched_actions, 
     AdsInsights.Field.video_p25_watched_actions, 
     AdsInsights.Field.video_p50_watched_actions, 
     AdsInsights.Field.video_p75_watched_actions, 
     AdsInsights.Field.video_p95_watched_actions,     
    ], 
    'time_range': {'since':'2017-08-01','until':'2017-08-01'}, 
} 

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()) 
print async_job.remote_read() 

最後の 'print'はreport_idを示します。

はその後CURLであなたは、ローカルにエクスポートするREPORT_ID、およびaccess_tokenはを必要とカール:

curl -G -d 'report_run_id=you_report_id' -d 'format=csv' 'https://www.facebook.com/ads/ads_insights/export_report?access_token=your_access_token' -o ReportCURL.csv 

私はこの情報がお役に立てば幸い!

関連する問題