2

Here is the code I wrote

NSString *str = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=CAADbwxRRgq8BANULcGGn3d4NPZB4LlP3tCL9YjYH3Nd0fD2XvgjG0qTECEmOsFhNhcu4NCdgYzQK3lYaATiedLRP4ZAIRgf8FBtDBYd22z5BrMabHlex12nZAbm8UfJTrPVRw5rjN8abi9"];


NSURL* url = [NSURL URLWithString:[str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSError* error = nil;
NSData* data = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error];
if (error) {
     NSLog(@"%@", [error localizedDescription]);
} else {
     NSLog(@"Data has loaded successfully.");
}

I got the error

Error Domain=NSCocoaErrorDomain Code=256 "The operation couldn’t be completed. (Cocoa error 256.)" UserInfo=0x218446a0

{NSURL=https://graph.facebook.com/me?access_token=CAADbwxRRgq8BANULcGGn3d4NPZB4LlP3tCL9YjYH3Nd0fD2XvgjG0qTECEmOsFhNhcu4NCdgYzQK3lYaATiedLRP4ZAIRgf8FBtDBYd22z5BrMabHlex12nZAbm8UfJTrPVRw5rjN8abi9ZBoVD1DYVZCo8hcZC0n2CnMyk3ryeCQntRpdZCc2e}
Shubhank
  • 21,721
  • 8
  • 65
  • 83
anuj
  • 1,010
  • 2
  • 11
  • 26

2 Answers2

4

Try:

NSString *str = [NSString stringWithFormat:@"https://graph.facebook.com/me?access_token=CAADbwxRRgq8BANULcGGn3d4NPZB4LlP3tCL9YjYH3Nd0fD2XvgjG0qTECEmOsFhNhcu4NCdgYzQK3lYaATiedLRP4ZAIRgf8FBtDBYd22z5BrMabHlex12nZAbm8UfJTrPVRw5rjN8abi9"];


NSURL* url = [NSURL URLWithString:[str stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

NSError* error = nil;
NSData* data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30] returningResponse:nil error:&error];

if (error) {
    NSLog(@"%@", [error localizedDescription]);
} else {
    NSLog(@"Data has loaded successfully.");
}

Albeit, I have no idea why your other request fails. Error code 256 isn't very descriptive.

mmackh
  • 3,550
  • 3
  • 35
  • 51
1

Here is a nice explanation of why NSCocoaErrorDomain occurs.

NSData dataWithContentsOfURL: not returning data for URL that shows in browser

Read it and see if any of the suggestions in that answer might be useful to you.

Community
  • 1
  • 1
anirudh
  • 4,116
  • 2
  • 20
  • 35