facebook-python-business-sdk icon indicating copy to clipboard operation
facebook-python-business-sdk copied to clipboard

Why create_photo can't not support "files" keyword argument ?

Open Onyx-Nostalgia opened this issue 10 months ago • 1 comments

I'm trying to upload an image from my local (not a URL) and I'm wondering why page.create_photo only supports using a URL???

I read the Doc in this section api_update and create_xxx support a files keyword argument

The sentence that says

api_update and create_xxx support a files keyword argument...

but page.create_photo does not support the files keyword argument, so I want to know why.🤔

My Problem code:

photo = page.create_photo(
                files=[photo_path],
                params={
                    "published": False,
                    "temporary": True,
                }
            )

THIS Error found:

TypeError: Page.create_photo() got an unexpected keyword argument 'files'

Why don't you add request.add_files(files) to create_photo method?? Is it the same reason for deprecating the various remote_xxx as well? Because I noticed that the method that is being deprecated also calls request.add_files(files) at the end.

Image

Onyx-Nostalgia avatar Feb 24 '25 21:02 Onyx-Nostalgia

My workaround is to use pending=True and request.add_files() outside the lib instead.

😎 IT WORK !!

my sample code:

photo_path = 'path/to/photo/f.png'

request = page.create_photo(
            params={
                "published": False,
                "temporary": True,
            },
            pending=True,
        )
request.add_files([photo_path])
page.assure_call()
photo = request.execute()

but have warning

/site-packages/facebook_business/utils/api_utils.py:16: UserWarning: Endpoint photos cannot upload files
  warnings.warn(message)

I understand that photos cannot upload multiple files, but in the case of uploading one file at a time, there is no problem.


As I am currently unaware of the rationale behind the decision not to include the request.add_files code (and error exceptions and other issues related to file upload restrictions), I am hesitant to create PR. to address this at this time.

But for anyone who is experiencing the same problem as me, I think my sample code might be of some help.

Onyx-Nostalgia avatar Feb 24 '25 22:02 Onyx-Nostalgia