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.
- # Input Parameters
- $developerToken = "12240-*****iPR2NWpZVtnbXYw"
- $messageID="1079916111"
- $headers = @{ Authorization=("Bearer " + $developerToken) }
- $likesCount=0;
-
-
- Function GetLikes($pageNo)
- {
- #page parameter- Programmatically paginate through the users in the network. 50 users will be shown per page.
- $uri="https://www.yammer.com/api/v1/users/liked_message/" + $messageID +".json?page=" + $pageNo
-
- # Invoke Web Request
- $webRequest = Invoke-WebRequest –Uri $uri –Method Get -Headers $headers
-
- # Check whether the status code is 200
- if ($webRequest.StatusCode -eq 200) {
-
- # Converts a JSON-formatted string to a custom object or a hash table.
- $results = $webRequest.Content | ConvertFrom-Json
-
- # Get the total number of count
- $likesCount=$likesCount+$results.users.length
-
-
- # Loop through all the messages
- $results.users | ForEach-Object {
- $user = $_
- # Display the User full name
- Write-Host -ForegroundColor Green $user.full_name
- }
-
- # Check if there are more items available
- if($results.more_available)
- {
- GetLikes($pageNo+1)
- }
- else
- {
- write-host -ForegroundColor Magenta "Total number of likes for this message: " $likesCount
- }
- }
- else {
- Write-Host -ForegroundColor Yellow "An error has occurred: " + $webRequest.StatusCode + " Description " + $webRequest.Status
- }
- }
-
- # Call the function
- GetLikes(1)
Open PowerShell window and run the following command.
folderlocation – LikesPerMessage.ps1 file's location
Run the following command.
Thus, in this blog, you saw how to get the statistics of likes per message in Yammer using PowerShell.