-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfb.sh
executable file
·48 lines (36 loc) · 1016 Bytes
/
fb.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
function downloadPhoto {
output_dir=$1
photo_id=$2
token=$3
echo Downloading photo $photo_id to $output_dir
photo_json=`curl -sS -X GET "https://graph.facebook.com/v2.6/$photo_id?fields=images&access_token=$token"`
photo_url=`jq -rM '.images|max_by(.width)|.source' <<< $photo_json`
curl -sS -o $output_dir/$photo_id.jpg -X GET "$photo_url"
}
function downloadPhotos {
output_dir=$1
json=$2
token=$3
photos=(`jq -rM '.data|.[]|.id' <<< $json`)
for i in ${photos[@]};
do
downloadPhoto $output_dir $i $token
done
}
album_id=$1
output_dir=$2
token=`cat .fb_access_token`
limit=100
next_page_url="https://graph.facebook.com/v2.6/$album_id/photos?fields=link&limit=$limit&access_token=$token"
until [[ $next_page_url == 'null' ]]
do
echo
echo Reading photos list from $next_page_url
json=`curl -sS -X GET $next_page_url`
echo
echo Downloading photos...
downloadPhotos $output_dir $json $token
next_page_url=`jq -rM .paging.next <<< $json`
done
exit 0