How To Get The Likes Per Message In Yammer Using PowerShell

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

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