Created
August 6, 2014 01:35
-
-
Save togakangaroo/bec695f4398973f54c32 to your computer and use it in GitHub Desktop.
Get a bunch of data from facebook and dump it to a powershell file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$tokens = cat .\facebook-tokens.csv | |
pushd | |
$wc = New-Object Net.WebClient | |
mkdir infos | |
cd infos | |
$cntr = 0 | |
foreach($t in $tokens) { | |
$cntr += 1 | |
Write-Host "Downloading $cntr of $($tokens.Length) - $t" | |
$url = "https://graph.facebook.com/me?access_token=$t" | |
$wc.DownloadString($url) | Out-File "$t.json" | |
} | |
popd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$jsonFiles = ls .\infos #| select -first 10 | |
$tokens = $jsonFiles | select -ExpandProperty Name | %{ ($_ -replace "json", "")} | |
$jsons = $jsonFiles | select | cat | ConvertFrom-Json | |
$cnt = 0 | |
$convertedObj = foreach($obj in $jsons) { | |
$hash = @{} | |
foreach($prop in $obj.psobject.properties) { | |
if($prop.TypeNameOfValue -eq 'System.String') { | |
$hash[$prop.Name] = $prop.Value | |
} else { | |
$hash[$prop.Name] = ($prop.Value | ConvertTo-Json -Compress) | |
} | |
} | |
if($obj.location) { | |
$hash.location_name = $obj.location.Name | |
$hash.location_id = $obj.location.Id | |
} | |
$hash.token = $tokens[$cnt] | |
$cnt += 1 | |
new-object psobject -Property $hash | |
} | |
$convertedObj | Export-Csv ./infos.csv | |
edit ./infos.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment