Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 获取Facebook好友列表并在自定义视图中显示?_Ios_Objective C_Ios7_Facebook Sdk 3.0_Facebook Friends - Fatal编程技术网

Ios 获取Facebook好友列表并在自定义视图中显示?

Ios 获取Facebook好友列表并在自定义视图中显示?,ios,objective-c,ios7,facebook-sdk-3.0,facebook-friends,Ios,Objective C,Ios7,Facebook Sdk 3.0,Facebook Friends,我正在尝试获取FaceBook好友列表,并将其显示在自定义视图中,如“foresqure应用程序” 我说的“foursquare”是什么意思?请求许可并在应用程序内的墙上发布,而不将应用程序留在浏览器或应用程序Facebook上?之后,应用程序将获取所有好友并在自定义tableView中显示 以下是我所尝试的: if (!FBSession.activeSession.isOpen) { // if the session is closed, then we open it here

我正在尝试获取FaceBook好友列表,并将其显示在自定义视图中,如“foresqure应用程序”

我说的“foursquare”是什么意思?请求许可并在应用程序内的墙上发布,而不将应用程序留在浏览器或应用程序Facebook上?之后,应用程序将获取所有好友并在自定义tableView中显示

以下是我所尝试的:

if (!FBSession.activeSession.isOpen) {
    // if the session is closed, then we open it here, and establish a handler for state changes
    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile", @"user_friends"]
                                       allowLoginUI:YES
                                  completionHandler:^(FBSession *session,
                                                      FBSessionState state,
                                                      NSError *error) {
                                      if (error) {
                                          UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
                                                                                              message:error.localizedDescription
                                                                                             delegate:nil
                                                                                    cancelButtonTitle:@"OK"
                                                                                    otherButtonTitles:nil];
                                          [alertView show];
                                      } else if (session.isOpen) {
                                          //[self pickFriendsButtonClick:sender];
                                          NSLog(@"aaaa");
                                          FBRequest* friendsRequest = [FBRequest requestForMyFriends];
                                          [friendsRequest startWithCompletionHandler: ^(FBRequestConnection *connection,
                                                                                        NSDictionary* result,
                                                                                        NSError *error) {
                                              NSArray* friends = [result objectForKey:@"data"];
                                              NSLog(@"Found: %i friends", friends.count);
                                              for (NSDictionary<FBGraphUser>* friend in friends) {
                                                  NSLog(@"I have a friend named %@ with id %@", friend.name, friend.id);
                                              }
                                          }];
                                      }
                                  }];

}
if(!FBSession.activeSession.isOpen){
//如果会话已关闭,那么我们将在此处打开它,并为状态更改建立一个处理程序
[FBSession openActiveSessionWithReadPermissions:@[@“公共”配置文件、@“用户朋友”]
阿洛洛洛吉努伊:是的
completionHandler:^(FBSession*会话,
FBSessionState州,
N错误*错误){
如果(错误){
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@“错误”
消息:error.localizedDescription
代表:无
取消按钮:@“确定”
其他按钮:无];
[警报视图显示];
}else if(session.isOpen){
//[自选好友按钮单击:发件人];
NSLog(@“aaaa”);
FBRequest*friendsRequest=[FBRequestFormyFriends];
[FriendsRequestStartWithCompletionHandler:^(FBRequestConnection*连接,
NSDictionary*结果,
N错误*错误){
NSArray*friends=[result objectForKey:@“data”];
NSLog(@“找到:%i个朋友”,朋友数);
用于(NSDictionary*朋友中的朋友){
NSLog(@“我有一个名为%@且id为%@”、friend.name、friend.id的朋友);
}
}];
}
}];
}
在这种情况下,它将打开safari以请求不在应用程序内的权限,并且friend array允许nill或count=0。

尝试此代码

首先像这样调用这个方法

[self FBFriendList];
并添加这两种方法

-(void)FBFriendList
{
if (!FBSession.activeSession.isOpen)
{
    // if the session is closed, then we open it here, and establish a handler for state changes

    [FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession *session,FBSessionState state, NSError *error)
     {
         if (error)
         {
             UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
             [alertView show];
             [alertView release];
         }
         else if(session.isOpen)
         {
             [self FBFriendList];
             [self fb_frnd_use_this_app];
         }
     }];

    return;
}
}

-(void)fb_frnd_use_this_app
   {
    FBRequest *request =  [FBRequest  requestWithGraphPath:@"me/friends"
                                                parameters:@{@"fields":@"name,installed,first_name,picture"}
                                                HTTPMethod:@"GET"];

    [request startWithCompletionHandler:^(FBRequestConnection *connection,
                                          id result,
                                          NSError *error)
     {


         NSLog(@"%@",result);
         int count = 0;
         NSMutableArray *frnd_arr = [result objectForKey:@"data"];
         for (int i = 0; i < [frnd_arr count]; i++)
         {
             NSLog(@"%@",frnd_arr);
             count++;
         }

         NSLog(@"%@",app.Arr_Facebook_Frnd);
         app.fbfriendCount =[NSString stringWithFormat:@"%d",count];

     }];
}
-(void)FBFriendList
{
如果(!FBSession.activeSession.isOpen)
{
//如果会话已关闭,那么我们将在此处打开它,并为状态更改建立一个处理程序
[FBSession openActiveSessionWithReadPermissions:nil allowLoginUI:YES completionHandler:^(FBSession*会话,FBSessionState,NSError*错误)
{
如果(错误)
{
UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@“错误”消息:Error.localizedDescription委托:nil cancelButtonTitle:@“确定”其他ButtonTitles:nil];
[警报视图显示];
[警报视图发布];
}
else if(session.isOpen)
{
[自友名单];
[自我fb首次使用此应用程序];
}
}];
回来
}
}
-(无效)fb\u首次使用\u此应用程序
{
FBRequest*request=[FBRequestRequestWithGraphPath:@“我/朋友”
参数:@{@“字段”:@“名称,已安装,名字,图片”}
HTTPMethod:@“获取”];
[请求开始完成处理程序:^(FBRequestConnection*连接,
身份证结果,
N错误*错误)
{
NSLog(@“%@”,结果);
整数计数=0;
NSMutableArray*frnd_arr=[result objectForKey:@“data”];
对于(int i=0;i<[frn_arr count];i++)
{
NSLog(@“%@”,frnd_arr);
计数++;
}
NSLog(@“%@”,app.Arr\u Facebook\u Frnd);
app.fbfriendCount=[NSString stringWithFormat:@“%d”,count];
}];
}

希望这段代码对您有用。

相同的结果打开:打开safari请求许可,这不是我想要的:(@Omarj权限是获取facebook好友列表的必备权限。我知道,我正在尝试的是获得类似Foursqure应用程序的权限查看我所附的照片?@Omarj我不明白什么?首先,openActiveSessionWithReadPermissions块中的代码从未调用过?甚至NSLog。/@Darshankunjadia在我的mac中检查此代码是完美的。我只更改我的facebook应用程序id并获取所有好友列表。当我忘记检查本机iOS应用程序(在facebook开发者页面)并键入我的捆绑包id时,我出现了此错误,该id与Xcode项目中的捆绑包标识符相同。(最后包括你的项目名称。)我在Facebook开发者页面上也设置了启用沙盒模式的设置,我也禁用了沙盒模式来完成这项工作。