簡體   English   中英

iPhone開發者使用fbconnect api獲取用戶個人資料名稱,電子郵件

[英]iphone dev get user profile name, email using fbconnect api

我正在用它從我的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 ,請不要調用它。 向導,我已經在這里待了很長時間了。 提前致謝。 問候,薩德。

嘗試這種方式:

[_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
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM