查看完整版本: [-- [已经解决]请教一个关于facebook获取好友的邮箱地址的问题。 --]

CocoaChina 开发讨论区 -> iOS开发讨论区 -> [已经解决]请教一个关于facebook获取好友的邮箱地址的问题。 [打印本页] 登录 -> 注册 -> 回复主题 -> 发表主题

ally1981 2010-03-18 11:53

[已经解决]请教一个关于facebook获取好友的邮箱地址的问题。

我想实现这个功能,登陆上facebook,并获取好友的列表,然后选择一个好友,对这个好友发邮件。
目前其它的功能都实现了,就是不知道如何获取好友的邮箱地址。
贴下我的代码。

- (void)getUserName {
    NSString *fql = [NSString localizedStringWithFormat: @"SELECT uid FROM user WHERE is_app_user = 1 AND uid IN (SELECT uid2 FROM friend WHERE uid1 = %lld)",[FBSession session].uid];
    
    
    NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
    [[FBRequest requestWithDelegate:self] call:@"facebook.friends.get" params:params];
}

- (void)request:(FBRequest*)request didLoad:(id)result
{
    if ([request.method isEqualToString:@"facebook.fql.query"]) {
        NSArray* users = result;
        NSDictionary* user = [users objectAtIndex:0];
        NSString* name = [user objectForKey:@"name"];
        
        _label.text = [NSString stringWithFormat:@"Logged in as %@", name];
    }
    else if ([request.method isEqualToString:@"facebook.users.setStatus"])
    {
        NSString* success = result;
        if ([success isEqualToString:@"1"])
        {
            _label.text = [NSString stringWithFormat:@"Status successfully set"];
        }
        else
        {
            _label.text = [NSString stringWithFormat:@"Problem setting status"];
        }
    }
    else if ([request.method isEqualToString:@"facebook.friends.get"])
    {
        if(myList==nil)
        {
            NSArray* users = result;
            myList =[[NSArray alloc] initWithArray: users];
            for(NSInteger i=0;i<[users count];i++)
            {
                NSDictionary* user = [users objectAtIndex:i];
                NSString* uid = [user objectForKey:@"uid"];
                NSString* fql = [NSString stringWithFormat:@"select name from user where uid == %@", uid];
                NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
                [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
            }
        }
        else
        {
            NSArray* users = result;
            NSDictionary* user = [users objectAtIndex:0];
            NSString* name = [user objectForKey:@"name"];
            //txtView.text=[NSString       localizedStringWithFormat:@"%@%@,\n",txtView.text,name];
            NSLog(name);
        }
    }
}


在使用if ([request.method isEqualToString:@"facebook.fql.query"]) 以后,获得的user
通过NSString* name = [user objectForKey:@"name"]; 可以获得名字,但是邮箱地址用什么获取呢?
有做过的朋友帮忙说下好吧。

ally1981 2010-03-18 13:36
自己顶一下!!

iamjiex 2010-03-18 13:50
之前研究过facebook的api,确实不能获得好友的邮箱。

ally1981 2010-03-18 14:18
我又做了一些工作,发现facebook的user table中有email的属性,但是现在获取不了,我修改的部分如下

if(myList==nil)
        {
            NSArray* users = result;
            myList =[[NSArray alloc] initWithArray: users];
            for(NSInteger i=0;i<[users count];i++)
            {
                NSDictionary* user = [users objectAtIndex:i];
                
                NSString* uid = [user objectForKey:@"uid"];
                NSString* fql = [NSString stringWithFormat:@"select name,email from user where uid == %@", uid];
                NSDictionary* params = [NSDictionary dictionaryWithObject:fql forKey:@"query"];
                [[FBRequest requestWithDelegate:self] call:@"facebook.fql.query" params:params];
            }
        }

NSString* fql = [NSString stringWithFormat:@"select name,email from user where uid == %@", uid];中,我增加了一个email的属性,于是在

if ([request.method isEqualToString:@"facebook.fql.query"]) {
        NSArray* users = result;
        NSDictionary* user = [users objectAtIndex:0];
        NSString* name = [user objectForKey:@"name"];
        NSString* email = [user objectForKey:@"email"];
        NSArray* key = [user allKeys];
        for(NSString* ini in key)
        {
            NSLog(ini);
        }
        
        _label.text = [NSString stringWithFormat:@"Logged in as %@", name];
    }

中,我打印user的所有key值,发现里面有email的属性。但是这个属性接受不了,用NSSting和NSURL都不行。

ally1981 2010-03-22 14:11
算是解决问题了。因为我查阅了facebook的官方说明。应该是不能获取mail地址,因为用户会隐藏。
所以最后的做法,是从本地发送图片或文字到facebook的自己的wall上。
下载最新的facebook connect 1。1版本。自带demo.

songjiangvip 2010-04-11 13:45
用户被禁言,该主题自动屏蔽!

假面 2010-04-22 17:42
感谢强大的楼住

baoyy 2010-06-02 15:33
除了能获取facebook好友的name,还能获取什么信息啊?
有关于好友数据库表的信息吗?

庚午子李 2012-11-20 16:17
能不能把分享图片和文字的的case 给我发一个,facebook,twitter 都需要


查看完整版本: [-- [已经解决]请教一个关于facebook获取好友的邮箱地址的问题。 --] [-- top --]



Powered by PHPWind v7.5 SP3 Code ©2003-2010 PHPWind
Gzip disabled

You can contact us