1

I am working with facebook apis

I am trying to fetch attributes of an image with id '105502842870274' for this I tried to create a url like this

NSString *firstComponent=@"https://graph.facebook.com/105502842870274?access_token=";
firstComponent=[firstComponent stringByAppendingFormat:[NSString stringWithFormat:@"%@",_accessToken]];

NSURL *url = [NSURL URLWithString:firstComponent];

but every time url is passes as nil.

Please let me know if I am doing something wrong or suggest someother way to fetch attributes of an image.

Thanx in advance

Ankit Sachan
  • 7,690
  • 16
  • 63
  • 98
  • Im also facing this issue, problem seems to lies in stringByAppendingFormat ...append seems to like adds extra stuff – Saqib Saud Jun 02 '11 at 11:29

3 Answers3

1

try this

NSString *firstComponent=@"https://graph.facebook.com/105502842870274?access_token=";
firstComponent=[firstComponent stringByAppendingString:[NSString stringWithFormat:@"%@",_accessToken]];

NSURL *url = [NSURL URLWithString:firstComponent];
Rahul Vyas
  • 28,260
  • 49
  • 182
  • 256
1

You're just doing it too complicated, and it is in your extra code that you made an error.

You used stringByAppendingFormat instead of stringByAppendingString.

For an even easier solution, just do :

NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/105502842870274?access_token=%@", _accessToken]];

Or if you want to access the string later :

NSString* firstComponent = [NSString stringWithFormat:@"https://graph.facebook.com/105502842870274?access_token=%@", _accessToken]
NSURL* url = [NSURL URLWithString:firstComponent];
Jaffa
  • 12,442
  • 4
  • 49
  • 101
1

this will resolve your issue. Its html encoding problem.

firstComponent = [firstComponent stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

also look: reference page

Community
  • 1
  • 1
Saqib Saud
  • 2,799
  • 2
  • 27
  • 41