Неверный синтаксис API маркетинга в Facebook - PullRequest
0 голосов
/ 03 июля 2019

Я пытаюсь использовать 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 голосов
/ 03 июля 2019

Вы используете Python 3, поэтому вам нужно () для аргументов print, потому что теперь это функция.

...