首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >我在使用facebook时出错

我在使用facebook时出错
EN

Stack Overflow用户
提问于 2019-11-20 11:16:34
回答 2查看 1.7K关注 0票数 3
代码语言:javascript
复制
 File "SAMPLE_CODE.py", line 21, in <module>
    from facebookads.adobjects.adaccount import AdAccount
  File "/usr/local/lib/python3.7/site-packages/facebookads/adobjects/adaccount.py", line 1582
    def get_insights(self, fields=None, params=None, async=False, batch=None, pending=False):
                                                         ^
SyntaxError: invalid syntax

我正在尝试使用Facebook,并且得到了这个错误。不知道该怎么办。这是我第一次设置并尝试使用这个API。如能提供任何帮助,将不胜感激。

这是我想要运行的文件

“”蟒蛇“

代码语言:javascript
复制
# Copyright 2014 Facebook, Inc.

# 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 = 'token'
ad_account_id = 'id'
app_secret = 'secret'
app_id = 'id'
FacebookAdsApi.init(access_token=access_token)

fields = [
    'reach',
    'delivery',
    'cost_per_result',
    'cpp',
    'cpm',
    'cost_per_action_type:page_engagement',
    'purchase_roas:omni_purchase',
    'website_purchase_roas:offsite_conversion_fb_pixel_purchase',
    'mobile_app_purchase_roas:app_custom_event_fb_mobile_purchase',
    'campaign_group_name',
]
params = {
    'level': 'ad',
    'filtering': [{'field':'delivery_info','operator':'IN','value':['active']}],
    'breakdowns': ['days_1'],
    'time_range': {'since':'2019-11-14','until':'2019-11-21'},
}
print(AdAccount(ad_account_id).get_insights(
    fields=fields,
    params=params,
))

""“

下面是另一个堆栈溢出问题,其中async= False也是错误

Problem with connect facebookads library for extract data from Facebook with Marketing API using Python

有人能解释一下这是怎么回事吗?

谢谢

我使用pyenv和Homebrew下载了3.6Python版本,并试图再次运行该文件,但我得到了一个新的错误代码。

""“

代码语言:javascript
复制
Kiefer's Macbook Pro:facebook-python-business-sdk kiefergallant$ python3.6 SAMPLE_CODE.py 
/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/utils/api_utils.py:30: UserWarning: value of breakdowns might not be compatible.  Expect list<breakdowns_enum>;  got <class 'list'>
  warnings.warn(message)
/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/utils/api_utils.py:30: UserWarning: insights does not allow field delivery
  warnings.warn(message)
/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_result
  warnings.warn(message)
/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/utils/api_utils.py:30: UserWarning: insights does not allow field cost_per_action_type:page_engagement
  warnings.warn(message)
/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/utils/api_utils.py:30: UserWarning: insights does not allow field purchase_roas:omni_purchase
  warnings.warn(message)
/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/utils/api_utils.py:30: UserWarning: insights does not allow field website_purchase_roas:offsite_conversion_fb_pixel_purchase
  warnings.warn(message)
/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/utils/api_utils.py:30: UserWarning: insights does not allow field mobile_app_purchase_roas:app_custom_event_fb_mobile_purchase
  warnings.warn(message)
/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/utils/api_utils.py:30: UserWarning: insights does not allow field campaign_group_name
  warnings.warn(message)
Traceback (most recent call last):
  File "SAMPLE_CODE.py", line 51, in <module>
    params=params
  File "/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/adobjects/adaccount.py", line 1639, in get_insights
    return request.execute()
  File "/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/api.py", line 664, in execute
    cursor.load_next_page()
  File "/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/api.py", line 851, in load_next_page
    params=self.params,
  File "/Users/kiefergallant/.pyenv/versions/3.6.0/lib/python3.6/site-packages/facebookads/api.py", line 332, in call
    raise fb_response.error()
facebookads.exceptions.FacebookRequestError: 

  Message: Call was not successful
  Method:  GET
  Path:    https://graph.facebook.com/v2.11/act_423073558387349/insights
  Params:  {'level': 'ad', 'filtering': '[{"field":"delivery_info","operator":"IN","value":["active"]}]', 'breakdowns': '["days_1"]', 'time_range': '{"since":"2019-11-14","until":"2019-11-21"}', 'fields': 'reach,delivery,cost_per_result,cpp,cpm,cost_per_action_type:page_engagement,purchase_roas:omni_purchase,website_purchase_roas:offsite_conversion_fb_pixel_purchase,mobile_app_purchase_roas:app_custom_event_fb_mobile_purchase,campaign_group_name'}

  Status:  400
  Response:
    {
      "error": {
        "message": "(#2635) You are calling a deprecated version of the Ads API. Please update to the latest version: v5.0.",
        "type": "OAuthException",
        "code": 2635,
        "fbtrace_id": "AASs5AEHjZ0VOZrOfeNziJy"
      }
    }

""“

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-11-20 11:50:51

取自this Question

APIPython的版本不兼容。

这个错误是由async参数get_insights()引起的,因为Python3.7不再被允许,因为async现在是python的一个保留关键字。

解决方案:使用较早的版本(<3.7)或使用与Python3.7兼容的版本。

票数 1
EN

Stack Overflow用户

发布于 2020-07-13 16:20:20

尝试facebook_business而不是facebookads。见this

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58953071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档