【问题标题】:iphone dev get user profile name, email using fbconnect apiiphone dev 使用 fbconnect api 获取用户配置文件名称、电子邮件
【发布时间】:2012-07-18 04:37:17
【问题描述】:

我正在使用它在我的 iphone 应用程序上的 facebook 上发帖

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];
}

墙贴进展顺利,但现在我想获取用户的 facebook 个人资料名称和电子邮件,为此我正在用户登录后尝试该代码

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

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

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

但即使这个 fbrequest 委托方法 - (void)request:(FBRequest *)request didLoad:(id)result 也不起作用,它没有被调用,拜托。指导,我已经被困在这里很长时间了。提前致谢。问候,萨德。

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    试试这个方法:

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

    你会这样解析响应:

    - (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
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-05
      • 1970-01-01
      • 1970-01-01
      • 2017-10-20
      • 1970-01-01
      • 1970-01-01
      • 2022-08-08
      相关资源
      最近更新 更多