I am trying to post a photo to my apps facebook fan page and to the users wall also. I have been successful to post the photo on the users wall, but failed to post it in th
I would simply try to address the exception error. It is possible to post to your fan page news feed. It is NOT possible to post as the fan page itself, as that would require authentication (thus the access token requirement.. you have to be logged in as that user to post as them). @Igy already address this above.
However, you do not have code for where you are using the image picker to get the image. The exception you are getting is because you are trying to check the length on a UIImage object instead of the NSData object (which is what Facebook requires). To convert your image from the picker to data use the snippet below (replace the img variable with your UIImage).
NSData *imgData = UIImageJPEGRepresentation(img, 0);
// Now call to length by facebook SDK will work and the exception will not fail
NSLog(@"Size of Image(bytes):%d",[imgData length]);
This isn't currently (June 2012) possible because of a bug in the API: https://developers.facebook.com/bugs/206254392780441 has the details.
One workaround is to post to the /feed
connection of the page and attach an image to the feed story. That image won't be displayed as large as a proper photo upload, but should work OK.
That bug means that posting to the /PAGE_ID/photos
connection of a Page using a User access_token
will incorrectly upload the photo to the user's /photos
connection instead.
Posting to a page's /photos
connection will work as expected when using the Page's access_token
; the photo will appear on the page's photos page, on the page's timeline, and attributed to the Page itself (i.e 'from' the page)
If your app is specifically for adding content to a page, and has a server-side component, another workaround to get the photos from a user onto the page is to have the users supply a photo to you via your own interface (i.e upload it from the user's device to your server), and use one of the page admins' access_tokens
to get a Page access_token and make the upload that way.
Instead of using dialog, you can ask user to grant permission - publish_stream
(since there is a bug in dialog component, otherwise its not required)
Then you can post on a page wall (assuming page allows in page settings).
You can try using graph api explorer. You can change the page id and test by granting above permission in extended permission tab.
Note
One more thing you should remember is, you cannot send image data in picture parameter. You should provide link to the Image.
I think you are using wrong argument for posting the photo
You should should use @"url"
instead of @"picture"
I am not sure with this, but it might work .
I to had the same problem in javaScript , which was solved .
Please view here for referring to my problem