I am a newbie on iOS development, so I find no clue when error like this, the code is like:
- (void)postToWall {
FBStreamDialog *dialog = [[[FBStreamDialog alloc] init]
autorelease];
dialog.userMessagePrompt = @"Enter your message:";
dialog.attachment = [NSString
stringWithFormat:@"{\"name\":\"Facebook Connect for
iPhone\",\"href\":\"http://developers.facebook.com/
connect.phptab=iphone\",\"caption\":\"Caption\",
\"description\":\"Description\",\"media\":[{\"type\":
\"image\",\"src\":\"http://img40.yfrog.com/img40/
5914/iphoneconnectbtn.jpg\",\"href\":
\"http://developers.facebook.com/connect.php?
tab=iphone/\"}],\"properties\":{\"another link\":
{\"text\":\"Facebook home page\",\"href\":
\"http://www.facebook.com\"}}}"];
[dialog show];
}
I am trying to learn from a online tutorial about facebook connect, so I got this error in the code and the file includes:
import "FBSession.h" import "FBLoginButton.h"
Do you think it could be this causes the problem?
Either write the string in a single line, or add " to the end and beginning of each line:
dialog.attachment = [NSString
stringWithFormat:@"{\"name\":\"Facebook Connect for"
"iPhone\",\"href\":\"http://developers.facebook.com/"
"connect.phptab=iphone\",\"caption\":\"Caption\","
"\"description\":\"Description\",\"media\":[{\"type\":"
"\"image\",\"src\":\"http://img40.yfrog.com/img40/"
"5914/iphoneconnectbtn.jpg\",\"href\":"
"\"http://developers.facebook.com/connect.php?"
"tab=iphone/\"}],\"properties\":{\"another link\":"
"{\"text\":\"Facebook home page\",\"href\":"
"\"http://www.facebook.com\"}}}"];
Also, note that in this case you don't need to use stringWithFormat, you can create the string like this:
dialog.attachment = @"{\"name\":\"Facebook Connect for"
"iPhone\",\"href\":\"http://developers.facebook.com/"
"connect.phptab=iphone\",\"caption\":\"Caption\","
"\"description\":\"Description\",\"media\":[{\"type\":"
"\"image\",\"src\":\"http://img40.yfrog.com/img40/"
"5914/iphoneconnectbtn.jpg\",\"href\":"
"\"http://developers.facebook.com/connect.php?"
"tab=iphone/\"}],\"properties\":{\"another link\":"
"{\"text\":\"Facebook home page\",\"href\":"
"\"http://www.facebook.com\"}}}";
The only thing apparently wrong with the code you've posted is all of the line breaks in the middle of your long string. Also, using stringWithFormat is not necessary there. Also your first 'href' is missing a '?' from the GET query. So try this and see what happens:
dialog.attachment = @"{\"name\":\"Facebook Connect for iPhone\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone\",\"caption\":\"Caption\",\"description\":\"Description\",\"media\":[{\"type\":\"image\",\"src\":\"http://img40.yfrog.com/img40/5914/iphoneconnectbtn.jpg\",\"href\":\"http://developers.facebook.com/connect.php?tab=iphone/\"}],\"properties\":{\"another link\":{\"text\":\"Facebook home page\",\"href\":\"http://www.facebook.com\"}}}";
Or better yet, break all of your keys and values out into their own NSStrings and put the long string back together using stringWithFormat. Or even BETTER, create the whole thing in memory and use NSJSONSerialization to create your JSON string. It will be much cleaner and less prone to errors.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With