0

I'm successfully able to post to facebook using SLRequest, in the following way:

- (void)postScoreWithFBAccount:(ACAccount *)facebookAccount
{

    NSString *messageToPost = [self.myString stringByAppendingString:@"https://www.example.com"];

    NSDictionary *fbParameters = @{@"message": messageToPost};
    NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/feed"];

    SLRequest *updateFeedRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:feedURL parameters:fbParameters];
    updateFeedRequest.account = facebookAccount;
    [updateFeedRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
     {
         if (responseData )
         {
             NSLog(@"Received Response: %@", [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]);
             if (urlResponse.statusCode >= 200 && urlResponse.statusCode < 300)
                 {
                 }
             else
                 {
                     NSLog(@"HTTP %d Returned", urlResponse.statusCode);
                 }
         }
         else
         {
             [self showErrorAlertWithMessage:@"Unknown error occured, try again later!"];
         }
     }];
}

I thought I could simply attach a url by appending one to my message string. The problem is that even though it is recognized as a link on facebook, it doesn't show a preview when broswing on facebook, like other url's do. Does anyone know how I can attach a url similar to how the SLComposerViewController does it, but instead through SLRequest?

Rajat
  • 1,043
  • 12
  • 23
KingPolygon
  • 4,753
  • 7
  • 43
  • 72

1 Answers1

2

You can add another parameter to the /feed: link.

See here for the complete list of parameters.

Edit:

You can also add some og:tags in your url inside <head> that facebook will crawl and show by default in the feed:

<meta property="og:title" content="{your title here}" />
<meta property="og:description" content="{your description here}" />
<meta property="og:image" content="{your image here}" />

You can check what is facebook crawling from your site, here: Debugger

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • Perfect thanks! I'm attaching a link to my company's page. The problem is it's only showing up on my profile, and no one else can see it. The settings are set for my friends to see, both in code and in my timeline. Do you know what could be happening? – KingPolygon Apr 09 '14 at 06:05
  • 1
    I think they can't see it because you app is still in Sandbox mode most likely - only owners, devs, and testers can see it. – Andy Apr 09 '14 at 06:06
  • 1
    @asavu is right. Probably app is still in dev mode; change it to live in the app settings; under "Status and Review" – Sahil Mittal Apr 09 '14 at 06:08
  • 1
    Be careful about doing the full live mode though, if your app is still in early testing then ANY users following you will see your posts, so that may be something to consider. – Andy Apr 09 '14 at 06:09
  • 1
    @asavu yes of course. Its preferred to do so after your application is ready. – Sahil Mittal Apr 09 '14 at 06:10
  • Awesome thank you! In order to make it go live, do I need to submit it to the facebook app center for review? – KingPolygon Apr 09 '14 at 06:15
  • Nop. App Center is a different thing, just to list your app in the facebook app Center that's it. – Sahil Mittal Apr 09 '14 at 06:17