In this blog, you will see how to get the likes per message in Yammer using PowerShell.

Prerequisites

Go to https://www.yammer.com/client_applications and register an app.

Once the app is registered, generate a developer token.

Copy the below script and paste it in a Notepad. Save the file as LikesPerMessage.ps1.

  1. # Input Parameters
  2. $developerToken = "12240-*****iPR2NWpZVtnbXYw"
  3. $messageID="1079916111"
  4. $headers = @{ Authorization=("Bearer " + $developerToken) }
  5. $likesCount=0;
  6. Function GetLikes($pageNo)
  7. {
  8. #page parameter- Programmatically paginate through the users in the network. 50 users will be shown per page.
  9. $uri="https://www.yammer.com/api/v1/users/liked_message/" + $messageID +".json?page=" + $pageNo
  10. # Invoke Web Request
  11. $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers
  12. # Check whether the status code is 200
  13. if ($webRequest.StatusCode -eq 200) {
  14. # Converts a JSON-formatted string to a custom object or a hash table.
  15. $results = $webRequest.Content | ConvertFrom-Json
  16. # Get the total number of count
  17. $likesCount=$likesCount+$results.users.length
  18. # Loop through all the messages
  19. $results.users | ForEach-Object {
  20. $user = $_
  21. # Display the User full name
  22. Write-Host -ForegroundColor Green $user.full_name
  23. }
  24. # Check if there are more items available
  25. if($results.more_available)
  26. {
  27. GetLikes($pageNo+1)
  28. }
  29. else
  30. {
  31. write-host -ForegroundColor Magenta "Total number of likes for this message: " $likesCount
  32. }
  33. }
  34. else {
  35. Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
  36. }
  37. }
  38. # Call the function
  39. GetLikes(1)

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – LikesPerMessage.ps1 file's location

Run the following command.

  1. >.\LikesPerMessage.ps1

Thus, in this blog, you saw how to get the statistics of likes per message in Yammer using PowerShell.