Facepy unable to upload image to Facebook

Go To StackoverFlow.com

2

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.

2012-04-05 03:11
by Chelonian
actually, I am even facing this error. So, I tried something line this graph.post(path="me/feed", picture=open("parrot.jpeg).read() Its not showing any error but posting an invalid image. me/feedSurya 2012-08-10 03:59
@Surya OK, no answers yet. Not sure if you edited it this way but if you did, please don't edit the title to include Django; that is, for my question, irrelevant. Thanks - Chelonian 2012-08-10 16:54
hey, I literally played all possibilities on this 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
@Surya Ah, interesting, but for me it doesn't help. I want to go from an image on my desktop to Facebook. If it is already an image online that means I've already posted it to another site only to have to read it back in with urllib2, which is absurd. I cannot understand why this works for the author of Facepy but not us - Chelonian 2012-08-10 17:17
Which access token have you been using, you want to post as a user to the page or as the page itself - phwd 2012-08-10 20:21
@phwd I'm not sure which access token it is, but I got it via this URL: 'https://www.facebook.com/dialog/oauth?clientid=xxxxxxxxxxxxxxx&scope=publishstream&redirecturi=https://www.facebook.com/connect/loginsuccess.html&response_type=token' I then logged in, agreed that it was OK to post to the wall, and got the access token. I don't understand your distinction between posting as the user or as the page itself. Ultimately I want users of desktop software to post photos to their Facebook page, if that helps to understand my need - Chelonian 2012-08-10 20:46
A Facebook page is a fan page, do you mean you want users to post to their personal profile/timeline or a fan page they own - phwd 2012-08-10 20:49
Probably both, though the first order of business would be the personal profile such that a person can share photos with one's friends (which is I believe is what I was trying to do). Later it would be great to be able to post to a fan page, too - Chelonian 2012-08-10 20:55
Try resetting your token / using a next one. The call works I've used it many times - phwd 2012-08-10 21:38
@phwd My old token had run out. I got a new one. I just tried it again. Same exact problem. Is it possible I am doing something wrong - Chelonian 2012-08-15 21:33
Could you post all your code from start (the import of facey till adding the token (use xxxxx) to the call) to finish? Maybe it might be a bug with your set that will have to escalate to the author or Facebook. But currently I cannot repro because it works for m - phwd 2012-08-15 22:37
@phwd OK, now posted everything I'm using - Chelonian 2012-08-15 23:20
I have tested against your full code and I see no errors. The photo updates to a user profile as it should.

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

@phwd Thanks for trying. Unfortunately, I tried the Graph API Explorer back in April; it only allows you to upload from a URL, which isn't testing my problem (uploading from a file on one's computer), though that did work. I don't have cURL, but I have seen others can use it to upload a photo from the computer. I am trying either Python 2.5 or 2.7.2, and neither work. I can't imagine the small Facepy script needs to be reinstalled, but I might as well try it. Frustrating. Thanks again for all your efforts - Chelonian 2012-08-17 01:06


2

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)
2017-02-10 15:16
by Jakub
Ads