Book Image

Mastering Social Media Mining with Python

By : Marco Bonzanini
Book Image

Mastering Social Media Mining with Python

By: Marco Bonzanini

Overview of this book

Your social media is filled with a wealth of hidden data – unlock it with the power of Python. Transform your understanding of your clients and customers when you use Python to solve the problems of understanding consumer behavior and turning raw data into actionable customer insights. This book will help you acquire and analyze data from leading social media sites. It will show you how to employ scientific Python tools to mine popular social websites such as Facebook, Twitter, Quora, and more. Explore the Python libraries used for social media mining, and get the tips, tricks, and insider insight you need to make the most of them. Discover how to develop data mining tools that use a social media API, and how to create your own data analysis projects using Python for clear insight from your social data.
Table of Contents (10 chapters)

Notes and activities from a Google+ page


After searching for a Google+ page and visualizing the results in a web GUI, we will proceed to download a list of activities for a given page. Activities are the Google+ equivalent of Facebook posts. By default, an activity is considered to be a note, that is, a piece of text shared on Google+.

The following script, gplus_get_page_activities.py, is used to collect a list of activities from a Google+ page:

# Chap05/gplus_get_page_activities.py 
import os 
import json 
from argparse import ArgumentParser 
from apiclient.discovery import build 
 
def get_parser(): 
  parser = ArgumentParser() 
  parser.add_argument('--page') 
  parser.add_argument('--max-results', type=int, default=100) 
  return parser 
 
if __name__ == '__main__': 
  api_key = os.environ.get('GOOGLE_API_KEY') 
  parser = get_parser() 
  args = parser.parse_args() 
 
  service = build('plus', 
                  'v1', 
                  developerKey=api_key) 
 
  activity_feed = service...