开发者

Django Facebook-SDK batch request

I am trying to make a post to multiple friends on facebook book using the python facebook-sdk library. Right now it does an individual request for each user. I was wondering how I would go about implementin开发者_如何学Gog batch requests with this library so that it can be done in a single request instead of multiple requests.


Facebook graph api has documentation on its batch request functionality. Have you tried using that? Another option would be to use the requests dialog.

I will warn you that you will want to be careful posting to multiple peoples walls (or friends walls in general) as that is a fast way to get your app blocked for spam.


I've been working in python based sdk for facebook that support batch requests https://github.com/zetahernandez/facebook-python-sdk

    from facebook_sdk.exceptions import FacebookResponseException
    from facebook_sdk.facebook import Facebook

    facebook = Facebook(
        app_id='{app_id}',
        app_secret='{app_secret}',
    )

    facebook.set_default_access_token(access_token='{access_token}')

    batch = {
        'photo-one': facebook.request(
            endpoint='/me/photos',
            params={
                'message': 'Foo photo.',
                'source': facebook.file_to_upload('path/to/foo.jpg'),
            },
        ),
        'photo-two': facebook.request(
            endpoint='/me/photos',
            params={
                'message': 'Bar photo.',
                'source': facebook.file_to_upload('path/to/bar.jpg'),
            },
        ),
        'photo-three': facebook.request(
            endpoint='/me/photos',
            params={
                'message': 'Other photo.',
                'source': facebook.file_to_upload('path/to/other.jpg'),
            },
        )
    }

    try:
        responses = facebook.send_batch_request(requests=batch)
    except FacebookResponseException as e:
        print e.message
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜