使用Twitter Rest API的Python代码错误

时间:2014-02-26 20:12:24

标签: python twitter

您好我有使用Twitter Rest API的作业。由于某种原因,我没有定义get_user_profile函数,我想知道为什么会这样。提前谢谢!

import twitter

def oauth_login():

    CONSUMER_KEY='***'
    CONSUMER_SECRET='**'
    OAUTH_TOKEN='***'
    OAUTH_TOKEN_SECRET='***'

auth = twitter.oauth.OAuth(OAUTH_TOKEN,OAUTH_TOKEN_SECRET,CONSUMER_KEY,CONSUMER_SECRET)

twitter_api = twitter.Twitter(auth=auth)
def get_user_profile(twitter_api, screen_names=None, user_ids=None):
        assert (screen_names !=None) != (uder_ids !=None), \
        "Must have screen_names or user_ids, but not both"

        items_to_info = {}

        items = screen_names or user_ids

        while len(items) > 0:
            items_str = ",".join([str(item) for item in items[:100]])
            items = items[100:]

            if screen_names:
                response = make_twitter_request(twitter_api.users.lookup, screen_name=items_str)

            else:
                response = make_twitter_request(twitter_api.users.lookup, user_id=items_str)

            for user_info in response:
                if screen_names:
                    items_to_info[user_info['screen_name']] = user_info
                else:
                    items_to_info[user_info['id']] = user_info

        return items_to_info


    #get user profile (9.17) get friends followers ids (9.19) 9.22S
return twitter_api

twitter_api = oauth_login()     打印twitter_api     print get_user_profile(twitter_api,screen_names = [" max_herbowy"])

0 个答案:

没有答案