Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save victorvogelpoel/58f006da77d0eb645832 to your computer and use it in GitHub Desktop.
Save victorvogelpoel/58f006da77d0eb645832 to your computer and use it in GitHub Desktop.
$slideshareUser = 'nccomms'
$slidedeckTitleFilter = 'SPCA2014*'
# Folder to download the slides to
$downloadfolder = 'C:\TEMP\SharePointConnect2014'
# Personal SlideShare API keys;
# apply for a key here: http://www.slideshare.net/developers/applyforapi
$slideShareAPIKey = 'YOUR_API_KEY' #PRIVATE
$slideShareSharedSecret = 'YOUR_SHARED_SECRET'
# Unix timestamp
$ts = [int][double]::Parse($(Get-Date -date (Get-Date).ToUniversalTime()-uformat %s))
# Create an SHA1 hash from the concatenation of the shared secret and the timestamp
$hash = ([System.Security.Cryptography.HashAlgorithm]::Create('SHA1').ComputeHash((New-Object System.Text.UTF8Encoding).GetBytes("$slideShareSharedSecret$ts")) | foreach { $_.ToString("x2") }) -join ''
$slideshareAPIGetSlideShowsForUserUri = "https://www.slideshare.net/api/2/get_slideshows_by_user?username_for=$slideshareUser&limit=9999&api_key=$slideShareAPIKey&hash=$hash&ts=$ts"
# Now query the SlideShare API for user NCCOMMS slides
Write-Host "Query SlideShare API: $slideshareAPIGetSlideShowsForUserUri"
$spa2014SlideData = Invoke-RestMethod -uri $slideshareAPIGetSlideShowsForUserUri
if ($spa2014SlideData.SlideShareServiceError)
{
Write-Host "ERROR while calling SlideShare API:" -ForegroundColor RED
$spa2014SlideData.SlideShareServiceError.Message | foreach { Write-Host $_.'#text' -ForegroundColor RED }
}
else
{
Write-Host "Downloading the slide decks..."
# Parsing the query results
foreach ($slidedeckEntry in ($spa2014SlideData.User.Slideshow | where { $_.Title -like $slidedeckTitleFilter }))
{
# Now process each slideshow entry
# Get the SlideShare PDF download url (which points to Amazon S3)
$sourceFile = $slidedeckEntry.DownloadUrl
# Extract the filename
$filename = (New-Object Uri($sourceFile)).Segments | select -last 1 # get filename part of the url
$destFilePath = (Join-Path $downloadfolder $filename)
Write-Host "From `"$SourceFile`"`nTo `"$destFilePath`""
# And download the deck file to the specified download folder
Invoke-WebRequest -Uri $sourceFile -OutFile $destFilePath
}
Write-Host "Completed downloading the slide decks."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment