简体   繁体   English

用户朋友在Facebook Sdk Graph Api v2中显示空白列表

[英]User friends are showing empty list in Facebook Sdk Graph Api v2

I have updated the version for the graph Api to v2 . 我已经将图表Api的版本更新为v2 Now the issue I am facing is,when I executed the following code It shows me empty array : 现在我面临的问题是,当我执行以下代码时,它显示了空数组:

FBRequest *friendsRequest = [FBRequest requestForMyFriends];
        [friendsRequest startWithCompletionHandler:^(FBRequestConnection *connection, NSDictionary<FBGraphUser> *result, NSError *error) {
            NSArray *friendshipid;
            NSString *username;
            if (!error) {
                NSLog(@"friends = %@", [result description]);

            }
            if (completion) {
                completion(friendshipid, username, error);
            }
        }];
    }
}

I got to know that facebook sdk had some changes for the user friends and now It has to take the permission for the user_friends , but I have no idea where to make changes to ask for Permission for user_friends 我知道facebook sdk为用户朋友做了一些更改,现在它必须获得user_friends的许可 ,但是我不知道在哪里进行更改以请求user_friends的 许可

You can use the given code snippet. 您可以使用给定的代码段。 Here, i have used the Classes of Social Framework to get the Facebook friends . 在这里,我使用了“ Social Framework类”来获取Facebook friends Hope it will work for you. 希望它对您有用。

- (void) connectWithFacebookFriends
{
    ACAccountStore *accountStore = [[ACAccountStore alloc] init];

    ACAccountType *accountTypeFacebook = [accountStore accountTypeWithAccountTypeIdentifier:
     ACAccountTypeIdentifierFacebook];

    NSDictionary *options = @{ACFacebookAppIdKey: kFaceBookId,
                              ACFacebookPermissionsKey: @[@"user_friends"],
                              ACFacebookAudienceKey: ACFacebookAudienceFriends
                              };

    [accountStore requestAccessToAccountsWithType:accountTypeFacebook
                                          options:options
                                       completion:^(BOOL granted, NSError *error)
    {
        if(granted) {

            NSArray *accounts = [accountStore
                                 accountsWithAccountType:accountTypeFacebook];
            ACAccount* facebookAccount = [accounts lastObject];
            NSString *acessToken = [NSString stringWithFormat:@"%@",facebookAccount.credential.oauthToken];
            NSDictionary *parameters = @{@"access_token": acessToken};

            NSURL *feedURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];

            SLRequest *feedRequest =
            [SLRequest requestForServiceType:SLServiceTypeFacebook
                               requestMethod:SLRequestMethodGET
                                         URL:feedURL
                                  parameters:parameters];

            [feedRequest performRequestWithHandler:^(NSData *responseData,
                                         NSHTTPURLResponse *urlResponse, NSError *error)
             {

                 NSString * str = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
                 DLog(@"%@",str);


                 NSLog(@"Request failed, %@", [urlResponse description]);
             }];
        } else {
            NSLog(@"Access Denied");
            NSLog(@"[%@]",[error localizedDescription]);

        }
    }];

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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