Exemplo n.º 1
0
        public async Task <Group> GetGroupsInCommunityAsync(string accessToken, string CommunityID)
        {
            Group groups = new Group();

            try
            {
                Group result = await _facebookClient.GetAsync <Group>(
                    accessToken, CommunityID + "/groups", "fields=id,cover,description,icon,is_workplace_default,name,owner,privacy,updated_time,archived&limit=400");

                if (result == null)
                {
                    return(new Group());
                }

                groups = result;

                while (result.paging != null && result.paging.next != null)
                {
                    if (result.paging.next == "")
                    {
                        return(groups);
                    }
                    result = await _facebookClient.GetAsyncDirectCall <Group>(accessToken, result.paging.next);

                    foreach (var r in result.data)
                    {
                        groups.data.Add(r);
                    }
                    if (result.paging.next == null)
                    {
                        return(groups);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Error on GetGroupsInCommunityAsync for " + CommunityID + " - " + ex.Message);
            }
            return(groups);
        }