我正在使用Python Twitter 工具 API尝试使用Twitter API v1.1 的lists.members.create_all将多个成员添加到列表中,但出现此错误:
Twitter 为 URL 发送状态 404:1.1/lists/members/create_all.json {"errors":[{"message":"抱歉,该页面不存在","code":34}]}
其他调用工作正常,将单个成员添加到列表工作正常。我的代码如下,希望有人能就如何正确使用lists.members.create_all 提供帮助!
#!/usr/bin/python
from twitter import *
OAUTH_TOKEN = 'my oauth token'
OAUTH_SECRET = 'my oauth secret'
CONSUMER_KEY = 'my consumer key'
CONSUMER_SECRET = 'my consumer secret'
USERNAME = "my username"
LIST_NAME = "fud"
def main():
twitter = Twitter(api_version='1.1', auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET, CONSUMER_KEY, CONSUMER_SECRET))
try:
# view a users lists
lists = twitter.lists.list(user=USERNAME)
# create a list
create_list = twitter.lists.create(name=LIST_NAME)
# view list members
list_members = twitter.lists.members(slug=LIST_NAME, owner_screen_name=USERNAME)
# add single user to list
twitter.lists.members.create(owner_screen_name=USERNAME, slug=LIST_NAME, screen_name="microsoft")
# add multiple users to list - fails !!!
twitter.lists.members.create_all(owner_screen_name=USERNAME, slug=LIST_NAME, screen_name="twitter,python")
#Produces error:
#Twitter sent status 404 for URL: 1.1/lists/members/create_all.json using parameters:
#{"errors":[{"message":"Sorry, that page does not exist","code":34}]}
except TwitterHTTPError as twerr:
import zlib
print twerr, zlib.decompress(twerr.response_data, 16+zlib.MAX_WBITS) # gunzip response error info
main()