Facebook Graph Batch, only takes top-level access_

2019-08-14 17:44发布

I'm using the Facebook Graph Batch API to send one message / different messages to registered people's FB walls. I'm defining an access_token for each user, and the obliged top-level access_token (used as fallback, according to the doc). For the latter I just use an access_token from the users listed in the batch.

The thing is that the only user recieving the message, is the one who's access_token I used as the top-level/fallback access_token. The other users get the "(#210) User not visible" error message. I'm using 3 test users setup at my app-roles.

Any idea what goes wrong here?

Here's my code (python) for generating one message to all registrants:

    for soc_reg in self.registrants:
        batch_item = {
            "method" : "POST",
            "relative_url" : FACEBOOK_URL_FEED % (soc_reg['uid']),
            "body" : Helper.toURL(publishParams),
            "access_token" : soc_reg['access_token'],
        }
        batch.append(batch_item)
    params = {
        "access_token" : self.registrants[0]['access_token'], # used as fallback
        "batch" : Helper.toJSON(batch),
    }

results in following value for "params":

{"access_token": "XYZ", "batch": "[{\"body\": \"caption=&message=is+not+a+test.%0D%0AWe%27re+just+rappin%27+to+the+beat%21&place=146270405429726&link=&description=\", \"access_token\": \"XYZ\", \"method\": \"POST\", \"relative_url\": \"/100003720771245/feed\"}, {\"body\": \"caption=&message=is+not+a+test.%0D%0AWe%27re+just+rappin%27+to+the+beat%21&place=146270405429726&link=&description=\", \"access_token\": \"ZYX\", \"method\": \"POST\", \"relative_url\": \"/100003671211957/feed\"}, {\"body\": \"caption=&message=is+not+a+test.%0D%0AWe%27re+just+rappin%27+to+the+beat%21&place=146270405429726&link=&description=\", \"access_token\": \"YZX\", \"method\": \"POST\", \"relative_url\": \"/100003683601909/feed\"}]"}

So the only user recieving the message is the one defined here: "access_token" : self.registrants[0]['access_token'] When I adjust the index, I can determine the one recieving the message ;)

1条回答
我命由我不由天
2楼-- · 2019-08-14 18:34

OK, seems like the documentation and the API itself are not corresponding: https://developers.facebook.com/bugs/212455918831996

Documentation says: relative_url => 'alias', 'body' => '{"access_token" => "..."}'

But only this ways seems to work: 'relative_url' => 'alias?access_token=...'

FB seemed to have confirmed the bug and put it on the 'wishlist', so far the latter is the way to go, works for me at least :)

查看更多
登录 后发表回答