简体   繁体   中英

iphone dev get user profile name, email using fbconnect api

i am using this for wall posting on facebook from my iphone app

kAppId =@"zsdgdfgjhjk";
    if (!kAppId) {
        NSLog(@"missing app id!");
        exit(1);
        return nil;
    }

    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        _permissions =  [[NSArray arrayWithObjects:
                          // @"read_stream", @"publish_stream", @"offline_access",@"user_events",@"friends_events",@"rsvp_event",nil] retain];
                          @"read_stream",@"email", @"publish_stream", @"offline_access",@"user_events",@"friends_events",@"rsvp_event",@"create_event",nil] retain];
        _facebook = [[Facebook alloc] initWithAppId:kAppId
                                        andDelegate:self];



- (IBAction)publishStream:(id)sender {

    SBJSON *jsonWriter = [[SBJSON new] autorelease];

    NSDictionary* actionLinks = [NSArray arrayWithObjects:[NSDictionary dictionaryWithObjectsAndKeys:
                                                           @"Always Running",@"text",@"http://itsti.me/",@"href", nil], nil];

    NSString *actionLinksStr = [jsonWriter stringWithObject:actionLinks];
    NSDictionary* attachment = [NSDictionary dictionaryWithObjectsAndKeys:
                                @"a long run", @"name",
                                @"The Facebook Running app", @"caption",
                                @"it is fun", @"description",
                                @"http://itsti.me/", @"href", nil];
    NSString *attachmentStr = [jsonWriter stringWithObject:attachment];
    NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"Share on Facebook",  @"user_message_prompt",
                                   actionLinksStr, @"action_links",
                                   attachmentStr, @"attachment",
                                   nil];

    [_facebook dialog:@"publish.stream"
            andParams:params
          andDelegate:self];
}

wall posting is going good but now i want to get user's facebook profile name plus email for this i am trying that code after user login

[_facebook requestWithGraphPath:@"me?fields=id,name,email" andDelegate:self];

and

- (void)request:(FBRequest *)request didLoad:(id)result
{
    if ([result isKindOfClass:[NSDictionary class]]){

        username = [result objectForKey:@"name"];
        }
}

but its not working even this fbrequest delegate method - (void)request:(FBRequest *)request didLoad:(id)result , it is not getting called, please. guide, I've been stuck here for a long time now. Thanks in advance. Regards, Saad.

Try this way:

[_facebook requestWithGraphPath:@"me" andDelegate:self];

and you will parse the response this way:

- (void)request:(FBRequest *)request didLoad:(id)result {
    if ([result isKindOfClass:[NSArray class]]){
        result = [result objectAtIndex:0];
    }
    if ([result objectForKey:@"owner"]) {
    }else{
                NSLog(@"response is %@", result);       
        NSString *email =[result objectForKey:@"email"];
        NSString *userFbId =[result objectForKey:@"id"];
                // grab other fields
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM