Search code examples
objective-cfacebook-graph-apicocos2d-iphone

Get Facebook Picture in Cocos2d-iphone V3


I'm trying to get the profile picture from Facebook, but I'm getting the following error:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage stringByStandardizingPath]:

This is my code:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=square", userid]];
 NSData *data = [NSData dataWithContentsOfURL:url];
 UIImage *image = [UIImage imageWithData:data];
 //convert UIImage to CCSprite
 CCTexture *texture = [CCTexture textureWithFile:image];
 CCSprite *sprite = [CCSprite spriteWithTexture:texture];
 sprite.position = ccp(winWidth*.5, winHeight*.5);

The error occurs in the UIImage *image line.


Solution

  • in your url userid is not valid so that this type of error is got. You have to enter Your userid to get picture.

    Enter your userid thats got when you are login.

    My userid : 100002026455444

    Url : http://graph.facebook.com/100002026455444/picture?type=square

    Now run that URL after enter your userid. you got Your picture.

    Code:

    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture?type=square",userid]];
     NSData *data = [NSData dataWithContentsOfURL:url];
     UIImage *image = [UIImage imageWithData:data];
     //convert UIImage to CCSprite
     CCTexture *texture = [CCTexture textureWithFile:image];
     CCSprite *sprite = [CCSprite spriteWithTexture:texture];
     sprite.position = ccp(winWidth*.5, winHeight*.5);