+ API
+ Added cursor parameter to API.friends and API.followers methods.
Note: page parameter is being deprecated by twitter on 10/26
+ + Update parsing to handle cursor responses.
+ When using 'cursor' parameter, the API method will return
+ a tuple with this format: (data, next_cursor, prev_cursor)
+ Calls not using the 'cursor' parameter are not changed in the way they return.
+ + API.friends_ids and API.followers_ids now return a list of integers.
+ Parser updated to handle cursor responses. See above.
+ Cursor
Added the Cursor object to help with pagination within the API.
Please see the pagination tutorial for more details.
+ This is the recommended way for using the 'page' and 'cursor' parameters.
1.0.1 -> 1.1
=======================
Parameters:
id or user_id or screen_name (One of these is required)
cursor
- Returns: json object
+ Returns: list<int>
http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-friends%C2%A0ids
"""
friends_ids = bind_api(
path = '/friends/ids.json',
- parser = parse_json,
+ parser = parse_ids,
allowed_param = ['id', 'user_id', 'screen_name', 'cursor']
)
Parameters:
id or user_id or screen_name (One of these is required)
cursor
- Returns: json object
+ Returns: list<int>
http://apiwiki.twitter.com/Twitter-REST-API-Method%3A-followers%C2%A0ids
"""
followers_ids = bind_api(
path = '/followers/ids.json',
- parser = parse_json,
+ parser = parse_ids,
allowed_param = ['id', 'user_id', 'screen_name', 'cursor']
)
except Exception:
raise TweepError("Failed to parse json response text")
+ # Parse cursor infomation
+ if isinstance(jobject, dict):
+ next_cursor = jobject.get('next_cursor')
+ prev_cursor = jobject.get('previous_cursor')
+ else:
+ next_cursor = None
+ prev_cursor = None
+
# Pass json object into parser
try:
- out = parser(jobject, api)
+ if next_cursor is not None and prev_cursor is not None:
+ out = parser(jobject, api), next_cursor, prev_cursor
+ else:
+ out = parser(jobject, api)
except Exception:
raise TweepError("Failed to parse json object")
from . models import models
+def _parse_cursor(obj):
+
+ return obj['next_cursor'], obj['prev_cursor']
+
def parse_json(obj, api):
return obj
def parse_users(obj, api):
+ if isinstance(obj, list) is False:
+ item_list = obj['users']
+ else:
+ item_list = obj
+
users = []
- for item in obj:
+ for item in item_list:
users.append(_parse_user(item, api))
return users
return source, target
+def parse_ids(obj, api):
+
+ if isinstance(obj, list) is False:
+ return obj['ids']
+ else:
+ return obj
+
def _parse_saved_search(obj, api):
ss = models['saved_search']()