Skip to content

Instantly share code, notes, and snippets.

@gloriouslyawkwardlife
Last active January 6, 2024 18:27
Show Gist options
  • Save gloriouslyawkwardlife/5e618cd1c0982604bde08d1e06ae6a93 to your computer and use it in GitHub Desktop.
Save gloriouslyawkwardlife/5e618cd1c0982604bde08d1e06ae6a93 to your computer and use it in GitHub Desktop.
Retrieves Facebook history as entries into the Mac version of DayOne
#!/usr/local/bin/pwsh
$access_token="<INSERT FACEBOOK ACCESS TOKEN HERE: https://developers.facebook.com/tools/accesstoken/"
$data = invoke-restmethod "https://graph.facebook.com/v18.0/me/posts?fields=title,application,backdated_time,caption,child_attachments,id,coordinates,created_time,description,event,full_picture,message,name,object_id,parent_id,place,scheduled_publish_time,status_type,story,type,updated_time,attachments,comments,link,permalink_url,reactions&limit=100&access_token=$access_token" -ErrorAction Stop
while ($true) {
foreach ($p in $data.data) {
if ($p.backdated_time -ne $null) {
$posttime = $p.backdated_time.toString('s').replace('T', ' ')
}
else {
$posttime = $p.created_time.toString('s').replace('T', ' ')
}
$text = "# Posted $($p.type) on Facebook"
if ($p.place -ne $null) {
$text += " from $($p.place.name)"
}
$text += "`n`n$($p.permalink_url)"
if ($p.link -ne $null) {
$text += "`n$($p.link)"
}
if ($p.message -ne $null) {
$text += "`n`n$($p.message)"
}
if ($p.description -ne $null) {
$text += "`n`n$($p.description)"
}
if ($p.full_picture -ne $null) {
$text += "`n`n![]($($p.full_picture))"
}
$text | Out-File /tmp/text.md
if ($p.place.location.latitude -ne $null -and $p.place.location.longitude -ne $null) {
Invoke-Expression "cat /tmp/text.md | /usr/local/bin/dayone2 -j 'Social Media' -t Facebook -d '$posttime' --coordinate $($p.place.location.latitude) $($p.place.location.longitude) new"
}
else {
Invoke-Expression "cat /tmp/text.md | /usr/local/bin/dayone2 -j 'Social Media' -t Facebook -d '$posttime' new"
}
Start-Sleep -Seconds 1
}
if ($data.paging.next -ne $null) {
Start-Sleep -Seconds 60
"Getting next page of data..."
$data = invoke-restmethod "$($data.paging.next)?limit=100" -ErrorAction Stop
}
else {
break
}
}
Remove-Item /tmp/text.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment