I'm trying to post a simple status update on the Facebook iOS SDK. At the moment, if I include the link parameter, everything will work:
NSMutableDictionary *params =
[NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Name here", #"name",
#"Caption here", #"caption",
#"Status update", #"description",
#"http://www.apple.com.",#"link",
nil];
[facebook dialog:#"feed"
andParams:params
andDelegate:self];
But once I remove link none of the remaining parameters are acknowledged and I'm left with a blank message. I simply want to perform the same sort of post you can achieve with Facebook request whereby providing a string for the message parameter is enough for the status update.
Not sure where I'm going wrong.
Actually posing of status messages with feed dialog isn't an option and it's actually not intended to be user like this.
You can consider one of the options:
Requesting publish_stream permission and than issue POST request to Graph API with message parameter (feed connection of user object), see statuses connection documentation (IMO it seems as an good way to go, if you don't afraid to ask publish_stream permission).
Open Facebook App with publishing view (and text pre-filled?), this is described in answer to "How to programmatically open iOS Facebook app with pre-populated status?"
Note: I'm not completely sure about inability to achieve this with feed dialog, so I may be wrong, anyone who know this isn't the case please correct me.
Related
I am working with Facebook SDK to share a message on the user's wall.
It was working fine until yesterday, but now it's broken.
I started getting message:
An error occured please try again later.
Did anything change on the Facebook side that prevents dialog to be present?
dictionary = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Lost Pet", #"name",
#"Help!", #"caption",
url, #"link",
[petInfo objectForKey:#"picture"], #"picture",
description, #"description",nil];
[facebook dialog:#"feed" andParams:dictionary andDelegate:self];
Any ideas how to approach it?
I tried to include app_id in the params.
It looks like your example is prefilling captions for posted images, which is a Facebook policy no-no - you might want to check your app for any developer alerts concerning this, which could be causing the error. You're also using the older "feed dialog" to post. The iOS 3.5 SDK included Native Share dialogs, which are much faster. Check the below resources for how to implement these:
https://developers.facebook.com/docs/howtos/share-native-dialogs-ios-sdk/
https://developers.facebook.com/docs/tutorial/iossdk/upgrading-from-3.2-to-3.5/
On the native iOS application code described at Facebook documentation http://developers.facebook.com/blog/post/2012/04/26/android-and-ios--discovery-via-requests-best-practices/ present very interesting usage of the deprecated app request dialog
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"Check out this awesome app.", #"message",
nil];
[self.facebook dialog:#"apprequests"
andParams:params
andDelegate:self];
It shows dialog but without any friends. I saw ton of troubles with this code at stackoverfloww but related to filters param. But actually I am not using filters at all. And it don't want to show list of the friends. Could it be related to SDK API change? Because several month ago it worked perfect.
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 the fan pages wall. (The user is not necessarily an admin or page owner, just the regular users. As the fan page has the option of anyone can post to it, it is not mandatory for the user to even like the page first. Right?)
After googling a while, I found this answer. According to it, I need an access_token of the fan page and an album_id to do so. But I can't find any clue about how to get them. So far I have tried this code:
if ([appDelegate.facebook isSessionValid])
{
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
resultImage, #"picture",
nil];
[appDelegate.facebook requestWithGraphPath:#"me/photos"
andParams:params
andHttpMethod:#"POST"
andDelegate:self]; // to post on users wall, works fine
NSString *path = [NSString stringWithFormat:#"my/accounts /fan_page_id?fields=access_toke/photos"];
[appDelegate.facebook setAccessToken: FACEBOOK_ACCESS_TOKEN];
[appDelegate.facebook requestWithGraphPath:path andParams:params andHttpMethod:#"POST" andDelegate:self]; // to post on fan page wall, this doesn't work
}
Can anyone help me with this? What am I missing here? Thanks in advance.
UPDATE
According to this answer, a regular user can not post a photo to the fan pages wall from an iOS app but can share the photo on it. Now, my question is, how do I accomplish posting the photo on the users wall and share it on the fan page wall at the same time? Is it possible? How do I share the photo on the fan page wall?
UPDATE 2
This answer and the question says that the regular users can post to a fan page wall via news feed, so i modified my code like this:
if ([appDelegate.facebook isSessionValid]) {
NSMutableDictionary *page_params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"fan_page_id", #"to",
#"Test", #"name",
#"Test", #"caption",
resultImage, #"picture",
nil];
[appDelegate.facebook dialog:#"feed"
andParams:page_params
andDelegate:self];
}
But, I keep getting this ridiculous error message and the app crashes:
-[UIImage length]: unrecognized selector sent to instance 0x24d110
2012-06-06 19:59:03.114 app_name[2739:707] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0x24d110'
What should I do now?
At this point after waiting so long, the question comes in my mind is, is this even possible? If so, how do I accomplish this task? And if not, then what are the alternatives? Please help.
Update 3
Just found that there is a known bug in both iOS sdk and the javascript sdk for posting dialogs in fan page wall. Is this true for image upload too? If anyone has a solution to avoid this bug, please help.
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 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]);
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
I can post a picture to FaceBook, without any user interaction, this way:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
facebookMessageTextView.text, #"message",
imageToSend, #"source",
nil];
FBRequest *request = [facebook requestWithGraphPath:#"me/photos" andParams:params andHttpMethod:#"POST" andDelegate:self];
Now what I would like to do is to display a standard FB dialog, so the user can modify the caption, and possibly decide to post to some other person's wall, or send as a private message. Such as (from the iPhone Facebook app):
I don't need the camera button as the image I pass in is not to be replaced. But I would like the user to be able to select to post to their wall, to another user's wall, change caption and privacy. How would I do so? And can I also select to send this image as a private message?
UPDATE: I can send a photo that is already uploaded to a user's album (via the above code), to their friend's timeline, using this:
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
#"http://www.bitsonthego.com", #"link",
[fbID objectForKey:#"id"], #"object_attachment",
#"my profile", #"name",
#"description", #"description",
#"name of the post", #"name",
#"caption of my post", #"caption",
facebookMessageTextView.text, #"message",
nil];
[facebook requestWithGraphPath:#"/{friend's id}/feed" andParams:params andHttpMethod:#"POST" andDelegate:self];
I still can't seem to use a dialog to specify the friend's in a standard Facebook UI, and it seems I will have to write my own UI to do this. Or?
Via the Facebook Graph API (the replacement to fbconnect) with publish_stream permissions, you are able to only post a photo to a user's wall or user's album.
Also the API does not allow sending of private messages. I am not aware of any iOS dialogs to assist you in doing this.
However, you might want to look at something called intents as it's called in the Android world, where your app says I want to let the user do this, and then the OS will give the user an option of what program they want to do it in if there are multiple programs. I found this S/O article on iphone equivalent to android intents for opening other apps. Maybe there's something in there you can use for iOS.
I'm currently working on an iOS app, and I use apprequests to bring up the dialog to send request. I can see everything working fine (I got the dialog complete thing) but user is not getting the request! I'm working with a test FB app (not public), I'm thinking if there's something I'm missing on setting up the FB app? Or is there a specify permission I have to enable?
Here is a little piece of my code:
-(void)appRequestsWithMessage:(NSString )message {
NSMutableDictionary params = [NSMutableDictionary dictionaryWithObjectsAndKeys: message, #"message", nil];
[facebook dialog:#"apprequests"
andParams:params
andDelegate:self];
}
To allow App Requests to be shown in Facebook, you have to enable "App on Facebook" in Apps Settings and supply a "Canvas URL" and a "Secured Canvas URL".
Have you added the receiving user as a tester on your Facebook app admin page? As long as you're in sandbox mode, only users added as testers (or any other position) can see, interact with and receive requests from our app.
Check the settings page for your app.