| 29 | |
| 30 | |
| 31 | def main(argv): |
| 32 | # Authenticate and construct service. |
| 33 | service, flags = sample_tools.init( |
| 34 | argv, |
| 35 | "plus", |
| 36 | "v1", |
| 37 | __doc__, |
| 38 | __file__, |
| 39 | scope="https://www.googleapis.com/auth/plus.me", |
| 40 | ) |
| 41 | |
| 42 | try: |
| 43 | person = service.people().get(userId="me").execute() |
| 44 | |
| 45 | print("Got your ID: %s" % person["displayName"]) |
| 46 | print() |
| 47 | print("%-040s -> %s" % ("[Activitity ID]", "[Content]")) |
| 48 | |
| 49 | # Don't execute the request until we reach the paging loop below. |
| 50 | request = service.activities().list(userId=person["id"], collection="public") |
| 51 | |
| 52 | # Loop over every activity and print the ID and a short snippet of content. |
| 53 | while request is not None: |
| 54 | activities_doc = request.execute() |
| 55 | for item in activities_doc.get("items", []): |
| 56 | print("%-040s -> %s" % (item["id"], item["object"]["content"][:30])) |
| 57 | |
| 58 | request = service.activities().list_next(request, activities_doc) |
| 59 | |
| 60 | except client.AccessTokenRefreshError: |
| 61 | print( |
| 62 | "The credentials have been revoked or expired, please re-run" |
| 63 | "the application to re-authorize." |
| 64 | ) |
| 65 | |
| 66 | |
| 67 | if __name__ == "__main__": |