Skip to content

Commit

Permalink
google+: stop using global batch API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Dec 8, 2018
1 parent 5cbe937 commit dfda375
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ Changelog
* Don't enclose bare URLs in`<`/`>` ([snarfed/bridgy#850](https://github.com/snarfed/bridgy/issues/850)).
* Atom:
* Bug fix for actors and attachments with multiple image URLs.
* Google+: switch from deprecated global API endpoint to G+ endpoint. Background in [snarfed/bridgy#846](https://github.com/snarfed/bridgy/issues/846), [Google blog post](https://developers.googleblog.com/2018/03/discontinuing-support-for-json-rpc-and.html) [and docs](https://developers.google.com/api-client-library/python/guide/batch).

### 1.14 - 2018-11-12
Add `delete()`. Currently includes Twitter and Flickr support.
* Instagram:
Expand Down
11 changes: 6 additions & 5 deletions granary/googleplus.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ def get_activities_response(self, user_id=None, group_id=None, app_id=None,
if user_id is None:
user_id = 'me'

api = self.auth_entity.api()
http = self.auth_entity.http()
if etag:
# monkey patch the ETag header in because google-api-python-client doesn't
Expand All @@ -119,14 +120,14 @@ def request_with_etag(*args, **kwargs):
# https://developers.google.com/+/api/latest/activities
try:
if activity_id:
call = self.auth_entity.api().activities().get(activityId=activity_id)
call = api.activities().get(activityId=activity_id)
activities = [call.execute(http=http)]
elif search_query:
call = self.auth_entity.api().activities().search(
call = api.activities().search(
query=search_query, maxResults=min(count, SEARCH_MAX_RESULTS))
activities = call.execute(http=http).get('items', [])
else:
call = self.auth_entity.api().activities().list(
call = api.activities().list(
userId=user_id, collection='public', maxResults=count)
resp = call.execute(http=http)
activities = resp.get('items', [])
Expand All @@ -147,13 +148,13 @@ def request_with_etag(*args, **kwargs):

# prepare batch API requests for comments, likes and reshares
# https://developers.google.com/api-client-library/python/guide/batch
batch = BatchHttpRequest()
batch = api.new_batch_http_request()
for activity in activities:
# comments
id = activity['id']
num_replies = activity.get('object', {}).get('replies', {}).get('totalItems')
if fetch_replies and num_replies and num_replies != cached.get('AGC ' + id):
call = self.auth_entity.api().comments().list(activityId=id, maxResults=500)
call = api.comments().list(activityId=id, maxResults=500)

def set_comments(_, resp, exc, activity=None):
obj = activity.get('object', {})
Expand Down

0 comments on commit dfda375

Please sign in to comment.