crino / instagram-ios-sdk

Instagram SDK for iOS
http://www.followgram.me
228 stars 63 forks source link

Get the user name #11

Closed sauloguerra closed 11 years ago

sauloguerra commented 11 years ago

Hey,

How can I get the username? I didn't find the point where I can get the "username" value... I just have the valid access token, but seems that they send the username at the response package... Look at the response format when we have authentication:

"If successful, this call will return a neatly packaged OAuth Token that you can use to make authenticated calls to the API. We also include the user who just authenticated for your convenience:" { "access_token": "fb2e77d.47a0479900504cb3ab4a1f626d174d2d", "user": { "id": "1574083", "username": "snoopdogg", "full_name": "Snoop Dogg", "profile_picture": "http://distillery.s3.amazonaws.com/profiles/profile_1574083_75sq_1295469061.jpg" } }

Could you help me?

Thanks!

crino commented 11 years ago

The library use 'Client-Side (Implicit) Authentication' and not the 'Server-side (Explicit) Flow'

hodgesmr commented 11 years ago

Implement the IGRequestDelegate:

// Uses our instagram instance to do a request
- (void) loadDisplayName {
    NSString* methodName = @"users/self";
    NSMutableDictionary* params = [[NSMutableDictionary alloc] init];
    [m_instagram requestWithMethodName:methodName params:params httpMethod:@"GET" delegate:self];
}

// IGRequestDelegate method that is called once we get a response
- (void)request:(IGRequest *)request didLoad:(id)result {
    NSDictionary* resultDictionary = (NSDictionary*) result;
    NSDictionary* data = [resultDictionary valueForKey:@"data"];
    NSString* username  = [data valueForKey:@"username"];
}