sns-sdks / python-facebook

A simple Python wrapper for facebook graph api :sparkles: :cake: :sparkles: .
https://sns-sdks.github.io/python-facebook/
322 stars 84 forks source link

False FacebookError exceptions raising #224

Closed OndraRehounek closed 1 year ago

OndraRehounek commented 1 year ago

Hello,

thank you for creating this wrapper around Meta API. We are facing some issues, which, as I believe, are connected with the library itself.

We are trying to create posts on both Instagram and Facebook. We are a bit suprised that library raises exceptions in cases when we successfully create a post.

For example if we create a POST with attached media, Meta API responds with 200 and post ID, but FacebookError is raised anyway:

"FacebookError(code=100,message=Tried accessing nonexisting field (attached_media) on node type (PagePost),type=FacebookApiException,fbtrace_id=Af2JVett85QUwBGNdExPwO9,original_response={'id': '115477344800609_149437988087315', 'post_supports_client_mutation_id': True})"

our code is somewhat inspired by examples but postly follows official Graph API docs

        for idx, response_dict in enumerate(img_response_list):
            post_data["attached_media[{}]".format(idx)] = json.dumps(
                {"media_fbid": response_dict["id"]}
            )

        return self.api.post_object(
            object_id=channel.uid,
            connection="feed",
            params={
                "fields": "id,message,created_time,from,attached_media",
            },
            data=post_data,
        )

If I do CURL version, it works just fine (using random photos for example):

           Create photo 1 request
           curl -i -X POST \
            -d "url=https://d15-a.sdn.cz/d_15/c_img_F_G/mTWfuE.jpeg?fl=cro,0,0,798,450%7Cres,1200,,1%7Cjpg,80,,1" \
            -d "published=false" \
            -d "access_token=CHANNEL_TOKEN" \
            -d "appsecret_proof=APP_SECRETS" \
            "https://graph.facebook.com/115477344800609/photos"

            Create photo 2 request
            curl -i -X POST \
            -d "url=https://tomanmotors.com/wp-content/uploads/2023/02/Dodge-Viper-Toman-Motors-2.jpg" \
            -d "published=false" \
            -d "access_token=CHANNEL_TOKEN" \
            -d "appsecret_proof=APP_SECRETS" \
            "https://graph.facebook.com/115477344800609/photos"

           Create actual Post request
           curl -i -X POST \
             -d "message=olalala" \
             -d "attached_media[0]={"media_fbid":"RESPONSE1[id]"}" \
             -d "attached_media[1]={"media_fbid":"RESPONSE2[id]"}" \
            -d "access_token=CHANNEL_TOKEN" \
            -d "appsecret_proof=APP_SECRETS" \
            "https://graph.facebook.com/v15.0/115477344800609/feed"

Maybe missing API v16 is the issue? However, I don't see any related changes in changelog.

MerleLiuKun commented 1 year ago

Sorry for late reply I will check this quickly!

MerleLiuKun commented 1 year ago

This issue because you used read-after-write

params={ "fields": "id,message,created_time,from,attached_media", },

the attached_media field not belong to the PagePost entity. just remove the field.

OndraRehounek commented 1 year ago

oh, I see, thank you!