Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash
set -e
# source $HOME/.google/api_keys
USER="$1"
if [ ! "$USER" ]
then
echo "Usage: google-plus-scrape-user USER_ID" 1>&2
exit 1
fi
if [ ! "$GOOGLE_PLUS_KEY" ]
then
echo "Error: Environment variable GOOGLE_PLUS_KEY must be set."
exit 1
fi
PREFIX="/tmp/google_plus_scraper/${USER}_$$"
BASE_URI="https://www.googleapis.com/plus/v1"
mkdir -p "$PREFIX"
echo "google-plus-scrape-user results being downloaded to $PREFIX" 1>&2
i=0
while True
do
((i+=1))
FILE="$PREFIX/$i"
curl -X GET "$BASE_URI/people/+$USER/activities/public?key=$GOOGLE_PLUS_KEY&maxResults=99&pageToken=$NEXT_PAGE_ID" > "$FILE"
cat "$FILE"
NEXT_PAGE_ID="$(jq -r '.nextPageToken // ""' < $FILE)"
if [ ! "$NEXT_PAGE_ID" ]
then
break
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment