<# .SYNOPSIS Gets the profile pictures of all the Facebooks friends of someone. .DESCRIPTION Uses the Graph API of Facebook to get someone's friends, and then downloads the default profile picture of all friends. .PARAMETER AccessToken The Facebook access token of the person in question, access token can be obtained e.g. from https://developers.facebook.com/tools/explorer .PARAMETER OutDir The directory where the pictures should be saved. In not specified, the pictures are saved in the current directory. .EXAMPLE .\Get-FaceBookFriendsPicture.ps1 -AccessToken XXXXXXXXX Downloads the pictures in the current directory. .EXAMPLE .\Get-FaceBookFriendsPicture.ps1 -AccessToken XXXXXXXXX -OutDir c:\pictures -Verbose Downloads the pictures to the c:\pictures directory, and prints out verbose information, e.g. URIs contacted. .NOTES - Author: Micskei Zoltan, 2013.02.28. - Pagination is not implemented, i.e. if friends data spans more than one page in the result, only the first page is processed See: https://developers.facebook.com/docs/reference/api/pagination/ #> [CmdletBinding()] param( [Parameter(Mandatory=$true)][string] $AccessToken, [Parameter(Mandatory=$false)][string] $OutDir = (Get-Location) ) # uri constants $FACEBOOK_API_URI = "https://graph.facebook.com/" $FACEBOOK_FRIENDS_SUFFIX = "me/friends?access_token=" $FACEBOOK_PICTURE_SUFFIX = "/picture?type=large" # check OutDir parameter if (! (Test-Path $OutDir)) { throw "$OutDir does not exists, correct -OutDir parameter's value!" } # download list of friends, result is a collection of # (data, paging), where data is a collection of (name,id) # of the friends of the AccessToken's person $friendsUri = $FACEBOOK_API_URI + $FACEBOOK_FRIENDS_SUFFIX + $AccessToken Write-Verbose "Dowloading friends data" $friends = Invoke-RestMethod -Uri $friendsUri -ErrorAction Stop if ($friends -ne $null) { $friends.data | % { $pictureUri = $FACEBOOK_API_URI + $_.id + $FACEBOOK_PICTURE_SUFFIX Write-Verbose "Downloading picture for $($_.name), uri:" Write-Verbose $pictureUri Invoke-WebRequest -Uri $pictureUri -OutFile (Join-Path $OutDir ($_.name + ".jpg")) -ErrorAction Continue } Write-Output "Saved $($friends.data.count) friend's pictures." } else { Write-Error "Could not download friends data!" }