skip to Main Content

I want to get info about ad campaign. And I start from this code to get campaign name. and I get this error :

Traceback (most recent call last):
  File "C:/Users/win7/PycharmProjects/API_Facebook/dd.py", line 2, in <module>
    from facebookads.adobjects.adaccount import AdAccount
  File "C:Userswin7AppDataLocalProgramsPythonPython37-32libsite-packagesfacebookadsadobjectsadaccount.py", line 1582
    def get_insights(self, fields=None, params=None, async=False, batch=None, pending=False):
                                                         ^
SyntaxError: invalid syntax
                                                     ^

What is may be reason? and if you want, can give code examples how can I get more info about campaign?
Click here to view image: code and error

3

Answers


  1. Try updating facebookads:

    $ pip install --upgrade facebookads
    

    I’m using facebookads==2.11.4.

    More info: https://pypi.org/project/facebookads/

    Login or Signup to reply.
  2. If you’re using Python 3.7, use async_, not only async.

    import os, re
    path = r"path facebookads"
    python_files = []
    
    for dirpath, dirnames, filenames in os.walk(path):
    
    for filename in filenames:
    if filename.endswith(".py"):
                python_files.append(os.path.join(dirpath, filename))
    
    for dirpath, dirnames, filenames in os.walk(path):
        for filename in filenames:
            if filename.endswith(".py"):
                python_files.append(os.path.join(dirpath, filename))
    
    for python_file in python_files:
    
        with open(python_file, "r") as f:
            text = f.read()
            revised_text = re.sub("async", "async_", text)
    
        with open(python_file, "w") as f:
            f.write(revised_text)
    
    Login or Signup to reply.
  3. They updated and renamed the library, now it’s facebook_ads and async argument was renamed to is_async

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search