• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2# -*- coding: utf-8 -*-
3#
4# Copyright 2014 Google Inc. All Rights Reserved.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10#      http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18"""Simple command-line sample for the Google+ API.
19
20Command-line application that retrieves the list of the user's posts."""
21from __future__ import print_function
22
23__author__ = 'jcgregorio@google.com (Joe Gregorio)'
24
25import sys
26
27from oauth2client import client
28from googleapiclient import sample_tools
29
30
31def main(argv):
32  # Authenticate and construct service.
33  service, flags = sample_tools.init(
34      argv, 'plus', 'v1', __doc__, __file__,
35      scope='https://www.googleapis.com/auth/plus.me')
36
37  try:
38    person = service.people().get(userId='me').execute()
39
40    print('Got your ID: %s' % person['displayName'])
41    print()
42    print('%-040s -> %s' % ('[Activitity ID]', '[Content]'))
43
44    # Don't execute the request until we reach the paging loop below.
45    request = service.activities().list(
46        userId=person['id'], collection='public')
47
48    # Loop over every activity and print the ID and a short snippet of content.
49    while request is not None:
50      activities_doc = request.execute()
51      for item in activities_doc.get('items', []):
52        print('%-040s -> %s' % (item['id'], item['object']['content'][:30]))
53
54      request = service.activities().list_next(request, activities_doc)
55
56  except client.AccessTokenRefreshError:
57    print ('The credentials have been revoked or expired, please re-run'
58      'the application to re-authorize.')
59
60if __name__ == '__main__':
61  main(sys.argv)
62