I'm trying to use Facepy, a sort of API for Facebook and Python, to simply post an image from my desktop to a Facebook page for which I have the authorization code and publish_stream and upload_photo permissions. (UPDATE: how do I verify that that is true?)
It's not working for me, though it is working for the author of Facepy. I'm at a loss for what is causing the issue. When I run this code, taken from the Facepy site (and using a .jpg on my computer):
UPDATE: This is the entirety of the code I am running:
from facepy import GraphAPI
print 'Trying Facebook page...'
my_token = 'xxxxxxxxxxxxxxxxx'
graph = GraphAPI(my_token)
# Get my latest posts
my_posts = graph.get("me/posts")
#Post a photo of a parrot
graph.post(path = "me/photos",source = open("python.png"))
print 'Done.'
Facepy returns this error:
Error: (#1) An unknown error occurred
I have tried it, unsuccessfully, with Python 2.5 and Python 2.7 on WinXP. Facepy can, however, get my latest posts, with graph.get('me/posts')
Any advice to get this to work would be appreciated.
graph.post()
and found one working method. If your image is a HttpResponse i.e, a web URL.. use graph.post(path="me/posts", source=urllib2.urlopen(imag url) )
this is workin - Surya 2012-08-10 17:04
You are most likely encountering a bug with this specific application. Try doing the call via the Graph API Explorer or cURL and see if you receive the same error. If you do, submit a bug. If you don't uninstall and reinstall your facepy.
Note: I am using Python 2.7. - phwd 2012-08-16 21:27
I had the same problem. And apparently found the answer.
According to GitHub page, a source
parameter needs a rb
mode:
graph.post(
path = 'me/photos',
source = open('parrot.jpg', 'rb')
Works for me (with Python 3 & Graph API 2.8).
To publish from URL, you can use url
:
par = {
"caption": "Some text",
"url": "https://example.com/1.jpg"}
send_post = graph.post(path='me/photos', **par)
graph.post(path="me/feed", picture=open("parrot.jpeg).read()
Its not showing any error but posting an invalid image.me/feed
Surya 2012-08-10 03:59