iOS -deprecated permission-facebook朋友生日使用Graph API

时间:2014-07-21 06:43:07

标签: ios objective-c swift facebook-graph-api

我是iOS新手。 我正试图从Facebook帐户获取所有朋友的生日。 我跟着Developers.facebook

我已请求所有必要的权限:user_friendsfriends_birthdayread_stream。我还在 Graph Api Explorer 中设置了权限。

首先我使用了图形路径:@"/me/friends?fields=name,id,birthday"。它只返回使用该应用的朋友名称和ID

我在网上搜索并试用了@"/me/taggable_friends"。在开发者网站中,我们只能访问此taggable_friends的三个字段:id,name,picture

我发现 facebook已弃用朋友详细信息权限。请参阅https://developers.facebook.com/docs/apps/upgrading

  

- (无效)pickFriendsClick   {

NSArray *permissions = [[NSArray alloc] initWithObjects: @"user_birthday",@"friends_hometown",@"friends_birthday",@"friends_location",nil];
if (![[FBSession activeSession]isOpen]) {

    if (APP.fb) {

        APP.fb =[[FBSession alloc]initWithPermissions:permissions];
    }
}

FBRequest *friendRequest = [FBRequest requestForGraphPath:@"/me/taggable_friends"];
[friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
    NSArray *data = [result objectForKey:@"data"];
    NSMutableArray *friends= [data mutableCopy];
    NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"updated_time" ascending:TRUE];
    [friends sortUsingDescriptors:[NSArray arrayWithObject:sortDescriptor]];

    for (FBGraphObject<FBGraphUser> *friend in friends) {
        NSLog(@"%@:%@", [friend name],[friend birthday]);
    }}]; }

2 个答案:

答案 0 :(得分:2)

已从v2.0中删除的完整权限列表。您的应用不应从Facebook Ver 2.0中询问以下任何内容:

create_event
manage_friendlists
read_requests
user_checkins
user_notes
user_online_presence
user_questions
user_subscriptions
xmpp_login
friends_about_me
friends_actions.books
friends_actions.fitness
friends_actions.music
friends_actions.news
friends_actions.video
friends_actions:APP_NAMESPACE
friends_activities
friends_birthday
friends_checkins
friends_education_history
friends_events
friends_games_activity
friends_groups
friends_hometown
friends_interests
friends_likes
friends_location
friends_notes
friends_online_presence
friends_photos
friends_questions
friends_relationships
friends_relationship_details
friends_religion_politics
friends_status
friends_subscriptions
friends_videos
friends_website
friends_work_history

参考:https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids

你只能获取朋友

1. id,name,picture only.

答案 1 :(得分:0)

我在新的facebook sdk中通过此代码获取了朋友。这可能会有所帮助。

NSArray *permissions =     [NSArray arrayWithObjects:@"email", @"user_birthday",@"friends_hometown",@"friends_birthday",@"friends_location",@"publish_stream",@"user_friends",@"public_profile",nil];

[self appDelegate].session = [[FBSession alloc] initWithPermissions:permissions];

[[self appDelegate].session openWithCompletionHandler:^(FBSession *session,
                                                        FBSessionState status,
                                                        NSError *error) {

    if(!error)
    {
        NSLog(@"success");
        [self fetchFriends];
    }
    else
    {
        NSLog(@"failure");
    }



}];

然后方法获取朋友是

-(void)fetchFriends
{
    if ([self appDelegate].session.isOpen)
    {
        [FBSession setActiveSession:[self appDelegate].session];
        FBRequest *friendRequest = [FBRequest requestForGraphPath:@"/me/friends?fields=name,picture,birthday,location"];
        [ friendRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            NSArray *data = [result objectForKey:@"data"];

            NSLog(@"response : %@",data);

            for (FBGraphObject<FBGraphUser> *friend in data)
            {
                NSLog(@"name : %@ , bday : %@", [friend name],[friend birthday]);

                [tempArray addObject:friend];
            }
        }];
    }
}