获取Facebook好友返回为空 [英] Get Facebook Friends returns empty

查看:122
本文介绍了获取Facebook好友返回为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取我的应用程序的好友列表,但这是控制台返回的内容:

I am trying to get a list of friends for my app, however this is what the console returns:

    {
    data =     (
    );
    summary =     {
        "total_count" = 1221;
    };

总数是正确的,但是没有显示我的任何朋友吗?

The total count is right but it doesn't show me any of my friends?

我已经在facebook开发人员门户上创建了两个测试用户,他们都已使用我的应用程序登录,并且他们是我在facebook上的朋友,他们的数据不应该显示吗?

I have created two test users on the facebook developer portal and they have both logged in with my app, and they are friends with me on facebook, shouldn't their data be showing?

这是我请求权限的代码,因此,每次用户登录时都会调用该类.

Here is my code for requesting the permissions and such, this class is called each time the user logs in.

@implementation UploadUser

NSString *userName;
NSString *userId;
NSString *userGender;
//UIImage *userPicture;
NSString *userPicture;

NSMutableURLRequest *urlRequest;

//NSData *imageData;
//NSData *pictureData;
//NSData *tempData;

//Retrieves users name, gender and id
-(void)getUserInfo {

    FBSDKGraphRequest *requestUser = [[FBSDKGraphRequest alloc]initWithGraphPath:@"me" parameters:nil];

    FBSDKGraphRequestConnection *connection = [[FBSDKGraphRequestConnection alloc] init];

    [connection addRequest:requestUser completionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
        userName = result[@"name"];
        userGender = result[@"gender"];
        userId = result[@"id"];

        if (connection) {

            if (!error) {

                [self setUserData];
                [self uploadUser];

            }
        }else if (!connection) {
            NSLog(@"Get User %@",error);
        }
    }];
    [connection start];


    //Get Friends
    FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
                                  initWithGraphPath:@"/me/friends"
                                  parameters:nil
                                  HTTPMethod:@"GET"];
    [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection,
                                          id result,
                                          NSError *error) {
        if (connection) {
            NSLog(@"Friends = %@",result);


        }else if (!connection) {
              NSLog(@"Get Friends Error");
        }
    }];



}


//Saves user data to class
-(void)setUserData {
    DataManager *dm = [DataManager sharedInstance];
    [dm setObject:userName forKey:@"userName"];
    [dm setObject:userGender forKey:@"userGender"];
    [dm setObject:userId forKey:@"userId"];



    NSLog(@"%@",userId);
    NSLog(@"%@",userName);
    NSLog(@"%@",userGender);
}

//Uploads user data online
-(void)uploadUser {
    PFUser *user = [PFUser currentUser];
    user[@"name"] = userName;
    user[@"id"] = userId;
    user[@"gender"] = userGender;
    [user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (succeeded) {
            NSLog(@"User Data Uploaded :)");
        } else {
            //Handle Error
            NSLog(@"User Upload Error... %@",error);
        }
    }];
}

为什么我的查询没有返回我的朋友?是因为我的朋友无权使用我的应用程序吗?是否没有正确询问我的权限?

Why are isn't my query returning my friends? Is it because my friends are not authorised to use my app? Is my permissions not being asked properly?

推荐答案

此外,您还可以使用Graph API Explorer来快速检查您的请求是否有效: https://developers.facebook.com/tools/explorer/

Also you can use Graph API Explorer in order to quickly check if your request works: https://developers.facebook.com/tools/explorer/

如果您想与朋友核对,您应该要求您的朋友也使用此链接并获得令牌.这样,facebook系统就会知道您的朋友在Graph API应用程序中登录,您将获得朋友列表.

If you want to check you friends you should ask your friend also use this link and get token. In this way the facebook system understand that your friend login in Graph API app and you will get the list of friends.

这篇关于获取Facebook好友返回为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆