Search code examples
pythonfacebookpygtk

How to implement a "send file to facebook" button in a native python gtk program?


I have simple python gtk program which I use on linux.

I would like to implement a "send file to facebook" button.

How can I do this?


Solution

  • You are not showing any code, so the question is probably more about whether it is possible. I am pretty sure it is possible.

    Facebook has a Python API: https://pypi.python.org/pypi/facebook-sdk

    There is an example for photo upload on that page:

    graph = facebook.GraphAPI(oauth_access_token)
    tags = json.dumps([{'x':50, 'y':50, tag_uid:12345},
                        {'x':10, 'y':60, tag_text:'a turtle'}])
    graph.put_photo(open('img.jpg'), 'Look at this cool photo!',
                        album_id_or_None, tags=tags)
    

    It seems you need to also read up on OAuth, and your program might need to have a place where it asks for a username and a password for the Facebook account. Probably you can also say tags=None if you just want to upload the picture.

    So all you probably need to do is put the above code into a function that accepts a path to a file. I would connect the button to a filechooser-dialog that returns the path to the file and then calls the upload function.