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


Python Twitter.post_tweet方法代码示例

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


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

示例1: test_post_only_text

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import post_tweet [as 别名]
 def test_post_only_text(self):
     t = Twitter(**twitter_access)
     tweet_text = "This is a test for plain text tweet at %r" % (_timenow())
     output = t.post_tweet(text=tweet_text)
     return_tweet_text = output.get('text')
     _add_to_test_tweets(output.get('id'), "text_only")
     self.assertEqual(tweet_text, return_tweet_text)
开发者ID:rakshit-agrawal,项目名称:python-twitter-apps,代码行数:9,代码来源:test_twitter.py

示例2: test_post_with_latlong_geo_true

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import post_tweet [as 别名]
    def test_post_with_latlong_geo_true(self):
        t = Twitter(**twitter_access)
        ll = (37.000880, -122.062309)
        tweet_text = "This is a test for plain text tweet with location at %r" % (_timenow())
        output = t.post_tweet(text=tweet_text, latlong=ll)
        return_tweet_text = output.get('text')
        _add_to_test_tweets(output.get('id'), "text_geo")

        self.assertEqual(tweet_text, return_tweet_text)
        if t.get_account_settings().get('geo_enabled'):
            return_ll = tuple(output['geo']['coordinates'])
            self.assertAlmostEqual(ll, return_ll)
开发者ID:rakshit-agrawal,项目名称:python-twitter-apps,代码行数:14,代码来源:test_twitter.py

示例3: test_post_with_media

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import post_tweet [as 别名]
    def test_post_with_media(self):
        t = Twitter(**twitter_access)
        tweet_text = "This is a test for tweet with 3 media at %r. Pictures from Pixabay." % (_timenow())
        jpegs = ['m01.jpg', 'm02.jpg', 'm03.jpg']
        media_list = [os.path.join('testing', i) for i in jpegs]
        output = t.post_tweet(text=tweet_text, media=media_list)
        return_tweet_text = output.get('text')
        _add_to_test_tweets(output.get('id'), "with_media")

        media_urls = [i['media_url_https'] for i in output['extended_entities']['media']]

        self.assertEqual(len(media_list), len(media_urls))
开发者ID:rakshit-agrawal,项目名称:python-twitter-apps,代码行数:14,代码来源:test_twitter.py

示例4: Twitter

# 需要导入模块: from twitter import Twitter [as 别名]
# 或者: from twitter.Twitter import post_tweet [as 别名]
-Rakshit Agrawal, 2016
"""
import datetime
import os
import time
from credentials import twitter_access, twitter_username
from twitter import Twitter

DATE_FORMAT = "%a, %d %b %Y %H:%M:%S"
TWEET_TEXT = "Hello! This is a test tweet using https://github.com/rakshit-agrawal/python-twitter-apps at %r UTC."

t = Twitter(**twitter_access)

# Post a simple tweet
tweet1 = t.post_tweet(text=TWEET_TEXT % (datetime.datetime.utcnow().strftime(DATE_FORMAT)))

time.sleep(2)
# Post a tweet with location
ll = (37.000880, -122.062309)
tweet2 = t.post_tweet(text=TWEET_TEXT % (datetime.datetime.utcnow().strftime(DATE_FORMAT)),
                      latlong=ll)

time.sleep(2)
# Post a tweet with sample media JPEGS
jpegs = ['m01.jpg', 'm02.jpg']
media_list = [os.path.join('testing', i) for i in jpegs]
tweet_text = TWEET_TEXT % (datetime.datetime.utcnow().strftime(DATE_FORMAT)) + " Pictures from Pixabay."
tweet3 = t.post_tweet(text=tweet_text,
                      media=media_list)
开发者ID:rakshit-agrawal,项目名称:python-twitter-apps,代码行数:31,代码来源:example.py


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