Siddharth
Siddharth

Reputation: 5219

Using Python facebook SDK for posting Open Graph action

Can I use the Facebook Python SDK to post a open graph action. As the python facebook SDK is now very old, how can I use that to post a open graph action - I could not find an example anywhere.

Upvotes: 1

Views: 1104

Answers (3)

zeta
zeta

Reputation: 39

you can use https://github.com/zetahernandez/facebook-python-sdk it supports doing simple request like

facebook = Facebook(
    app_id='{app_id}',
    app_secret='{app_secret}',
    default_graph_version='v2.5',
)

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

try:
    response = facebook.get(endpoint='/me?fields=id,name')
except FacebookResponseException as e:
    print e.message
else:
    print 'User name: %(name)s' % {'name': response.json_body.get('id')}

or request in batch

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

Upvotes: 0

Gordon Wrigley
Gordon Wrigley

Reputation: 11765

Using the facebook-sdk package from pip you can post an action with the put_object call

facebook.GraphAPI(token).put_object("me", "my_app:my_action", "my_object_type"="http://my_objects_url")

Upvotes: 1

Niraj Shah
Niraj Shah

Reputation: 15457

You can use the GraphAPI.request(self, path, args=None, post_args=None) function from the Python for Facebook 3rd party library (http://www.pythonforfacebook.com/). Just follow the documentation on the Facebook Developer Site to build the path, args and post_args needed to make the API call.

Upvotes: 1

Related Questions