Created
September 18, 2011 00:51
-
-
Save 1905/1224536 to your computer and use it in GitHub Desktop.
get actual user photo (profile picture) by user id from Vkontakte, Twitter, Facebook
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// get actual user picture from VKONTAKTE by UID | |
- (void)getUserPictureVK:(NSString*)uid | |
{ | |
NSString *requestURLstring = [NSString stringWithFormat:@"https://api.vkontakte.ru/method/getProfiles?uid=%@&fields=photo", uid]; | |
NSURL *requestURL = [NSURL URLWithString:requestURLstring]; | |
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestURL]; | |
[request setTimeoutInterval:10]; | |
AFJSONRequestOperation *operation = [AFJSONRequestOperation operationWithRequest:request | |
success:^(id JSON) { | |
DLog(@"JSON OK"); | |
[self setupVKphoto:JSON]; | |
} | |
failure:^(NSError *error) { | |
DLog(@"JSON FAIL: %@", error); | |
} | |
]; | |
NSOperationQueue *queue = [[[NSOperationQueue alloc] init] autorelease]; | |
[queue addOperation:operation]; | |
} | |
- (void)setupVKphoto:(id)JSON | |
{ | |
// in VK world user dict inside dict and inside array | |
id obj = [JSON valueForKeyPath:@"response"]; | |
if([obj isKindOfClass:[NSArray class]]) { | |
NSDictionary *userData = [NSDictionary dictionaryWithDictionary:[obj objectAtIndex:0]]; | |
NSString *userPhotoUrlString = [userData valueForKey:@"photo"]; | |
DLog(@"user photo: %@", userPhotoUrlString); | |
} | |
} | |
// get actual user picture from TWITTER by screen_name | |
- (void)getUserPictureTW:(NSString*)screenName | |
{ | |
//also http://api.twitter.com/1/users/profile_image/twitterapi.json | |
NSString *userPhotoUrlString = [NSString stringWithFormat:@"http://api.twitter.com/1/users/profile_image?screen_name=%@&size=normal", screenName]; | |
DLog(@"user photo: %@", userPhotoUrlString); | |
} | |
// get actual user picture from FACEBOOK by username | |
- (void)getUserPictureFB:(NSString *)username | |
{ | |
NSString *userPhotoUrlString = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture",username]; | |
DLog(@"user photo: %@", userPhotoUrlString); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Fcebook one not possible anymore, requires a token: https://developers.facebook.com/docs/graph-api/reference/v9.0/user/picture