ItsMeAgain
ItsMeAgain

Reputation: 595

formatting a url to appear as string in a facebook post

I am trying to post a link formatted as a string on facebook. Please see the relevant code below:

NSMutableDictionary* params = [[NSMutableDictionary alloc] init];

NSString *modifiedTitle = [NSString stringWithFormat:@"<a href= https://www.google.com> My App </a>"];
[params setObject:modifiedTitle forKey:@"message"];
[params setObject:UIImagePNGRepresentation(picture) forKey:@"picture"];


[FBRequestConnection startWithGraphPath:@"me/photos"
                             parameters:params
                             HTTPMethod:@"POST"
                      completionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)
         if (error)
     {
         //showing an alert for failure
         NSLog(@"ERROR in posting image to Facebook");
     }
     else
     {
         //showing an alert for success
         NSLog(@"Result after posting image successfully = %@",result);
     }
     // button.enabled = YES;
 }];

The message appeared as:

<a href= https://www.google.com> My App </a>

instead of

My App

Upvotes: 0

Views: 62

Answers (1)

Brooks Hanes
Brooks Hanes

Reputation: 425

For one thing, ensure you're posting an immmutable dictionary into the startWithGraph... method by using the copy method:

NSDictionary* paramsImmutable = params.copy;
[FBRequestConnection startWithGraphPath:@"me/photos"
                         parameters:paramsImmutable
                         HTTPMethod:@"POST"
                  completionHandler:^(FBRequestConnection *connection,
                                      id result,
                                      NSError *error)

That way you won't have any changes to worry about on that object during the method's lifetime.

Next, is your params including any sort of quotes around the url? I.e.

NSString *modifiedTitle = @"<a href='https://www.google.com'>My App</a>";

That's just a start.

Upvotes: 1

Related Questions