Facebook Marketing API语法错误

时间:2019-07-03 03:08:41

标签: python-3.x facebook-marketing-api

我正在尝试首次使用Facebook Marketing和AdInsights API。我是API编程的新手。我使用FB Developers快速入门工具为我生成了Python代码。

抛出语法错误。我已经导入了与此任务相关的所有库。

我尝试检查语法是否有变化。虽然找不到特别的东西。我已经屏蔽了所有访问代码。


# You are hereby granted a non-exclusive, worldwide, royalty-free license to
# use, copy, modify, and distribute this software in source code or binary
# form for use in connection with the web services and APIs provided by
# Facebook.

# As with any software that integrates with the Facebook platform, your use
# of this software is subject to the Facebook Developer Principles and
# Policies [http://developers.facebook.com/policy/]. This copyright notice
# 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 facebookads.adobjects.adaccount import AdAccount
from facebookads.adobjects.adsinsights import AdsInsights
from facebookads.api import FacebookAdsApi

access_token = '***'
ad_account_id = 'act_***'
app_secret = '***'
app_id = '***'
FacebookAdsApi.init(access_token=access_token)

fields = [
    'reach',
    'frequency',
    'impressions',
    'relevance_score:score',
    'spend',
    'campaign_group_name',
    'campaign_name',
    'adgroup_name',
    'actions:mobile_app_install',
    'cost_per_action_type:omni_app_install',
    'actions:page_engagement',
    'actions:like',
    'actions:comment',
    'actions:post_engagement',
    'actions:post_reaction',
    'actions:onsite_conversion_post_save',
    'actions:post',
    'video_continuous_2_sec_watched_actions:video_view',
    'actions:video_view',
    'video_10_sec_watched_actions:video_view',
    'video_p25_watched_actions:video_view',
    'video_p50_watched_actions:video_view',
    'video_p75_watched_actions:video_view',
    'video_p95_watched_actions:video_view',
    'video_p100_watched_actions:video_view',
    'video_avg_time_watched_actions:video_view',
    'video_play_actions:video_view',
    'actions:link_click',
]
params = {
    'level': 'ad',
    'filtering': [],
    'breakdowns': [],
    'time_range': {'since':'2019-07-02','until':'2019-07-03'},
}
print AdAccount(ad_account_id).get_insights(fields=fields,params=params)````



ERROR
File "<ipython-input-9-6dac1e060c63>", line 67
    print AdAccount(ad_account_id).get_insights(fields=fields,params=params)
                  ^
SyntaxError: invalid syntax

1 个答案:

答案 0 :(得分:0)

您正在使用Python 3,因此您需要在print的参数周围加上(),因为它现在是一个函数。