Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page LikeByInformation - Page.GetLikedByInformationAsync() is not retreiving any information about page likes #1395

Closed
1 task done
NishkalankBezawada opened this issue Feb 16, 2024 · 5 comments
Assignees
Labels
area: model 📐 Related to the core SDK models question Further information is requested

Comments

@NishkalankBezawada
Copy link

NishkalankBezawada commented Feb 16, 2024

Category

  • Bug

Describe the bug

I am trying to get the Page LikedByInformation as below,

var pageLikeInformation = clientSidePage.GetLikedByInformationAsync().GetAwaiter().GetResult();

But i get no results when using this.

I also used GetCommentsAsync() to get the comment collection which works fine.
var commentsCollection = clientSidePage.GetCommentsAsync().GetAwaiter().GetResult();

Below code is working and getting likedByInformation as well.
`
var pageNew = await pnpContext.Web.NewPageAsync();

            // Save the page
            await pageNew.SaveAsync("Pageb.aspx");

            // Publish the page, required before it can be liked
            await pageNew.PublishAsync();

            // Like the page
            await pageNew.LikeAsync();

            var pageLikeInformation = await pageNew.GetLikedByInformationAsync();
            bool pageLikedByCurrentUser = pageLikeInformation.IsLikedByUser;
            foreach (var likedByUser in pageLikeInformation.LikedBy.AsRequested())
            {
                // do something with the information about the user who liked this page
            }

`

Below code is not working,

`
var mypages = await pnpContext.Web.GetPagesAsync("TestingLikeInfo.aspx");
var pageABC = mypages.First();

            await pageABC.PublishAsync();
            ILikedByInformation likeInfo2 = await pageABC.GetLikedByInformationAsync();
            bool pageLikedByCurrentUser2 = likeInfo2.IsLikedByUser;

`

Expected behavior

await pageABC.GetLikedByInformationAsync(); should get LikedByInformation

Library

PnP.Core - 1.11.69-nightly

Thanks,
Nishkalank

@jansenbe jansenbe self-assigned this Feb 19, 2024
@jansenbe jansenbe added question Further information is requested area: model 📐 Related to the core SDK models labels Feb 19, 2024
@jansenbe
Copy link
Contributor

@NishkalankBezawada : not sure what the issue is here, I've tested https://github.com/pnp/pnpcore/blob/dev/src/sdk/PnP.Core.Test/SharePoint/PagesTests.cs#L2728-L2775 and this works fine. A page can be liked, the like can be retrieved and the page can be unliked.

If I try below then GetLikedByInformation returns on instance saying there are no likes on the page.

// Save the page
await newPage.SaveAsync(pageName);

// Publish the page, required before it can be liked
newPage.Publish();

// Like the page
//newPage.Like();

// Get a list of users who liked this page
var pageLikeInformation = newPage.GetLikedByInformation();

@NishkalankBezawada
Copy link
Author

NishkalankBezawada commented Feb 19, 2024

Thanks @jansenbe for your prompt reply.

I am trying to fetch a page LikedByInformation as below (which is having more than 3 likes),

var mypages =  await pnpContext.Web.GetPagesAsync("TestingLikeInfo.aspx");
var pageABC = mypages.First();
ILikedByInformation likeInfo = await pageABC.GetLikedByInformationAsync();

This should return me the LikedInformation of that particular page, but GetLikedByInformationAsync returns no likes on that particular page.

GetLikedByInformationAsync works only when i create it, save, publish it, and then like it as below

              var pageNew = await pnpContext.Web.NewPageAsync();

                // Save the page
                await pageNew.SaveAsync("Pageb.aspx");

                // Publish the page, required before it can be liked
                await pageNew.PublishAsync();

                // Like the page
                await pageNew.LikeAsync();

                var pageLikeInformation = await pageNew.GetLikedByInformationAsync();
                bool pageLikedByCurrentUser = pageLikeInformation.IsLikedByUser;
                foreach (var likedByUser in pageLikeInformation.LikedBy.AsRequested())
                {
                    // do something with the information about the user who liked this page
                }

Or is GetLikedByInformationAsync only works when a page is liked as pageNew.LikeAsync(); then retrieve the LikedByInformation and then unlike the page as pageNew.UnLikeAsync()?

@jansenbe
Copy link
Contributor

@NishkalankBezawada : thanks, I can now reproduce the issue you're seeing. Let me work on a fix

@NishkalankBezawada
Copy link
Author

@NishkalankBezawada : thanks, I can now reproduce the issue you're seeing. Let me work on a fix

Thanks once again Jensen @jansenbe

Regards,
Nish

@jansenbe
Copy link
Contributor

@NishkalankBezawada : I fixed this, please test again with the next nightly build. Will close this issue now, feel free to re-open in case the problem stays.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: model 📐 Related to the core SDK models question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants