我遇到了这样的问题,我用用户A关注了其他2个用户,同时让另外三个用户关注用户A,
在_Follower和_Followee中都可以查询到数据
想在代码中,得到关注人的信息的时候,用如下代码:
let currentUser: AVUser = AVUser.current()! //用户A
//获取关注用户A的人数
let followerQuery = AVQuery(className:"_Follower")
followerQuery.whereKey("user",equalTo: currentUser)
followerQuery.countObjectsInBackground({(count:Int,error:Error?) in
if error == nil {
header.followercountLbl.text = String(count) //
}
})
结果count 返回0,但是应该是3,在控制台可以看到数据
//获取用户A关注的人数
let followeeQuery = AVQuery(className: "_Followee")
followeeQuery.whereKey("user",equalTo: currentUser)
followeeQuery.countObjectsInBackground({(count:Int,error:Error?) in
if error == nil {
header.followingcountLbl.text = String(count) //
}
})
结果count返回了2,这是正确的。
所以,使用同样的查询,在_Followee中能得到正确的count,但在_Follower中就不行。
同样的问题在调用AVUser.current()?.getFollowers 时也会出现,就是找不到数据。但是调用AVUser.current()?.getFollowees就没有问题。

可以先检查一下是否是权限问题(可能因为权限的关系能查到的结果比预期的少)。

如仍有疑问,请提供以下信息以供排查:

  1. 应用的 AppID
  2. 开启调试日志后的完整请求日志
我检查了表的权限,所有的读、写、修改权限都是允许所有用户的,所以看起来不像权限问题
我的AppID是BvcgkxdRDlts836i0xKiFFxr-gzGzoHsz

AVUser.current()?.getFollowers (获取当前用户所关注的列表)方法为例,

        AVUser.current()?.getFollowers{(followers:[Any]?,error:Error?) in
            if error == nil && followers != nil {
                self.followerArray = followers! as! [AVUser]
                self.tableView.reloadData()
            } else {
                print(error?.localizedDescription)
            }
        }

执行后可以看到日志信息如下:

2020-06-13 22:22:11.215707+0800 MyInstegram[64506:4216391] [DEBUG] -[AVPaasClient performRequest:success:failure:wait:] [Line 609]

------ BEGIN LeanCloud REST Request -------
path: /1.1/classes/_Follower
curl: curl -i -k -X GET -G --compressed -H 'Accept: application/json' -H 'Content-Type: application/json; charset=utf-8' -H 'X-LC-Id: BvcgkxdRDlts836i0xKiFFxr-gzGzoHsz' -H 'X-LC-Prod: 1' -H 'Accept-Language: en;q=1' -H 'X-LC-Session: ykskv7gktvebu7jrv6x9o6e4r' -H 'Accept-Encoding: gzip' -H 'User-Agent: AVOS Cloud iOS-v7.3.1 SDK' --data-urlencode 'include=follower' --data-urlencode 'keys=follower' --data-urlencode 'where={"$and":[{"user":{"_type":"Pointer","className":"User","objectId":"5ec394973522a50006d6d266"}}]}' "https://BvcgkxdR.api.lncld.net/1.1/classes/_Follower"
------ END --------------------------------
2020-06-13 22:22:16.910238+0800 MyInstegram[64506:4216536] [DEBUG] -[AVPaasClient performRequest:success:failure:wait:]blockinvoke [Line 652]

------ BEGIN LeanCloud REST Response ------
path: /1.1/classes/_Follower
cost: 5694.303ms
response: {
results = (
);
}
------ END --------------------------------
(lldb)

返回的response中的results是没有任何数据的,但是在控制台中可以看到_Follower里应该有三条数据。
但是如果调用 AVUser.current()?.getFollowees (同时获取当前用户的粉丝和关注列表),

        AVUser.current()?.getFollowees{(followers:[Any]?,error:Error?) in
            if error == nil && followers != nil {
                self.followerArray = followers! as! [AVUser]
                self.tableView.reloadData()
            } else {
                print(error?.localizedDescription)
            }
        }

执行后就可以看到日志如下:

2020-06-13 22:25:30.419853+0800 MyInstegram[64506:4216391] [DEBUG] -[AVPaasClient performRequest:success:failure:wait:] [Line 609]

------ BEGIN LeanCloud REST Request -------
path: /1.1/classes/_Followee
curl: curl -i -k -X GET -G --compressed -H 'Accept: application/json' -H 'Content-Type: application/json; charset=utf-8' -H 'X-LC-Id: BvcgkxdRDlts836i0xKiFFxr-gzGzoHsz' -H 'X-LC-Prod: 1' -H 'Accept-Language: en;q=1' -H 'X-LC-Session: ykskv7gktvebu7jrv6x9o6e4r' -H 'Accept-Encoding: gzip' -H 'User-Agent: AVOS Cloud iOS-v7.3.1 SDK' --data-urlencode 'include=followee' --data-urlencode 'keys=followee' --data-urlencode 'where={"$and":[{"user":{"_type":"Pointer","className":"User","objectId":"5ec394973522a50006d6d266"}}]}' "https://BvcgkxdR.api.lncld.net/1.1/classes/_Followee"
------ END --------------------------------
2020-06-13 22:25:32.245397+0800 MyInstegram[64506:4218055] [DEBUG] -[AVPaasClient performRequest:success:failure:wait:]blockinvoke [Line 652]

------ BEGIN LeanCloud REST Response ------
path: /1.1/classes/_Followee
cost: 91.863ms
response: {
results = (
{
createdAt = "2020-06-09T05:54:50.667Z";
followee = {
"__type" = Pointer;
ava = {
"__type" = File;
bucket = BvcgkxdR;
createdAt = "2020-06-05T08:37:08.597Z";
key = "jvuEEaDvjVIgWCnC4uQrPNC.jpg";
metaData = {
"_checksum" = 9531fc8f6cf680f934bb9a244a73d608;
size = 242290;
};
"mime_type" = "image/jpeg";
name = "ava.jpg";
objectId = 5eda0434ba7dda00094ce587;
provider = qiniu;
updatedAt = "2020-06-05T08:37:08.597Z";
url = "http://lc-BvcgkxdR.cn-n1.lcfile.com/jvuEEaDvjVIgWCnC4uQrPNC.jpg";
};
className = "_User";
createdAt = "2020-06-05T08:37:09.039Z";
email = "zhangdan@sina.com";
emailVerified = 0;
fullname = zhangdan;
mobilePhoneVerified = 0;
objectId = 5eda04359cf15200063a238e;
updatedAt = "2020-06-05T08:37:09.039Z";
userinfo = mummy;
username = mom;
web = "www.iseeku.com";
};
objectId = 5edf242a3e8c5e000880f595;
updatedAt = "2020-06-09T05:54:50.667Z";
},
{
createdAt = "2020-06-09T05:58:23.083Z";
followee = {
"__type" = Pointer;
ava = {
"__type" = File;
bucket = BvcgkxdR;
createdAt = "2020-06-05T08:04:51.703Z";
key = "vV9zmRHSCmcHWHJfgevtBVD.jpg";
metaData = {
"_checksum" = 090d118c2d77e93a7bb3658076ddced2;
size = 124300;
};
"mime_type" = "image/jpeg";
name = "ava.jpg";
objectId = 5ed9fca3c14134000661c33e;
provider = qiniu;
updatedAt = "2020-06-05T08:04:51.703Z";
url = "http://lc-BvcgkxdR.cn-n1.lcfile.com/vV9zmRHSCmcHWHJfgevtBVD.jpg";
};
className = "_User";
createdAt = "2020-06-05T08:04:52.164Z";
email = "drgao1946@sina.com";
emailVerified = 0;
fullname = "gap urban";
mobilePhoneVerified = 0;
objectId = 5ed9fca4c14134000661c33f;
updatedAt = "2020-06-05T08:04:52.164Z";
userinfo = Grandpa;
username = DrGao;
web = "www.iseeku.com";
};
objectId = 5edf24ff9d7c3a0006ffda21;
updatedAt = "2020-06-09T05:58:23.083Z";
}
);
}
------ END --------------------------------

提交返回的response的results就有数据,和_Followee中查询到的结果也是一致的
这个可能是什么原因呢?

按 getFollowers 的条件,查到的这三条数据的 ACL 指定了不同的 User。

_Follower & _Followee 表的权限里还有一个 Friendship ACL 权限,您可以按需自行修改。

确实是这个问题,我刚才修正了后,已经可以看到数据了。谢谢! pray