当前位置: 首页>>代码示例>>Python>>正文


Python Twitter.login方法代码示例

本文整理汇总了Python中twitter.Twitter.login方法的典型用法代码示例。如果您正苦于以下问题:Python Twitter.login方法的具体用法?Python Twitter.login怎么用?Python Twitter.login使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twitter.Twitter的用法示例。


在下文中一共展示了Twitter.login方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import login [as 别名]
def main():
    if args.twitter:
        t = Twitter(args)
        t.login()
        t.get_tweepy_API()
        if args.command == 'read':
            t.read()
        elif args.command == 'post':
            t.post()
        else:
            t.delete()
 
    if args.facebook:
        f = Facebook(args)
        f.login()
        f.get_facepy_API()
        if args.command == 'read':
            f.read()
        elif args.command == 'post':
            f.post()
        else:
            f.delete()
开发者ID:mgzwarrior,项目名称:pshare,代码行数:24,代码来源:pshare.py

示例2: TestTwitter

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import login [as 别名]
class TestTwitter(unittest.TestCase):
    def setUp(self):
        # simulate "psh -t read" command args
        args = Namespace(cargs='home', command='read', facebook=False, media='', number=10, status='', twitter=True, verbose=False)
        self.t = Twitter(args)
        self.t.login()

    def test_login(self):
        # Tests login() & indirectly, known_user_auth()
        # and first_time_auth() by checking the access
        # token of 'self.auth'

        # read in access token from 'twitter-access-token.txt'
        with open('twitter-access-token.txt', 'r') as infile:
            content = infile.readlines()
        access_token = content[0].rstrip()
        access_token_secret = content[1].rstrip()
        self.assertEqual(self.t.auth.access_token, access_token)
        self.assertEqual(self.t.auth.access_token_secret, access_token_secret)

    def test_get_tweepy_API(self):
        # Tests get_tweepy_API & verify() indirectly

        self.assertFalse(isinstance(self.t.api, tweepy.API))
        self.t.get_tweepy_API()
        self.assertTrue(isinstance(self.t.api, tweepy.API))

    def test_statuses_to_tweets(self):
        self.t.get_tweepy_API()
        statuses = self.t.api.home_timeline(count=self.t.args.number)
        tweets = self.t.statuses_to_tweets(statuses)
        # check first element, assume the rest are the same
        self.assertTrue(isinstance(tweets[0], tweet.Tweet))

        tweets = self.t.statuses_to_tweets([])
        self.assertFalse(tweets)
开发者ID:mgzwarrior,项目名称:pshare,代码行数:38,代码来源:test_twitter.py


注:本文中的twitter.Twitter.login方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。