【问题标题】:Facebook Marketing API Incorrect SyntaxFacebook 营销 API 语法不正确
【发布时间】:2019-11-13 16:31:34
【问题描述】:

我是第一次尝试使用 Facebook 营销和 AdInsights API。我是 API 编程的新手。我使用 FB Developers QuickStart Tool 为我生成了 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

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

    • 我完全错过了。谢谢你。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多