Twitter 如何从直接消息中获取文本?

Twitter 如何从直接消息中获取文本?,twitter,tweepy,Twitter,Tweepy,这个问题与特维图书馆有关 我正在使用下面的命令获取收到的最新直接消息。我想获取用户id和消息文本并回复。 然而,我无法理解如何提取文本。有什么帮助吗 api.direct_messages(count=1) 只需打印消息,它就会返回以下内容: [DirectMessage(sender=User(statuses_count=8452, verified=False, _json={'default_profile_image': False, 'statuses_count': 8452,

这个问题与特维图书馆有关

我正在使用下面的命令获取收到的最新直接消息。我想获取用户id和消息文本并回复。 然而,我无法理解如何提取文本。有什么帮助吗

api.direct_messages(count=1)
只需打印消息,它就会返回以下内容:

[DirectMessage(sender=User(statuses_count=8452, verified=False, _json={'default_profile_image': False, 'statuses_count': 8452, 'following': True, 'verified': False, 'entities': {'description': {'urls': []}}, 'profile_background_image_url': 'http://pbs.twimg.com/profile_background_images/7904887943048/ab960e4a9bfeb7dd71c91e5b4f5c9dd1.jpeg', 'screen_name': 'xxxtnb', 'is_translation_enabled': False, 'id': 448743511, 'id_str': '448473511', 'notifications': False, 'name': 'Xxx Xxx', 'profile_text_color': '1C1F23', 'profile_background_tile': True, 'location': 'xxxx', 'default_profile': False, 'profile_use_background_image': True, 'profile_sidebar_fill_color': 'C9C9C9', 'lang': 'en', 'protected': False, 'has_extended_profile': False, 'profile_background_color': '07090B', 'is_translator': False, 'created_at': 'Fri Jun 05 11:39:26 +0000 2009', 'contributors_enabled': False, 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/3788000004442443400505954094/26ac579d33b26ee9e6748a3563fe3754dc_normal.png', 'profile_banner_url': 'https://pbs.twimg.com/profile_banners/44873556411/135934873965', 'time_zone': 'xxxx', 'description': '|DSECRIPTION|', 'listed_count': 2, 'profile_sidebar_border_color': 'FFFFFF', 'followers_count': 296, 'favourites_count': 19, 'geo_enabled': False, 'friends_count': 2332, 'profile_background_image_url_https': 'https://pbs.twimg.com/profile_background_images/79048873328/ab960e433a9bfeb7dd71c91e5b4f5c9dd1.jpeg', 'follow_request_sent': False, 'utc_offset': 25200, 'profile_image_url': 'http://pbs.twimg.com/profile_images/378800000324505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png', 'url': None, 'profile_link_color': 'C34242'}, id=44843473511, screen_name='xxxtnb', profile_background_image_url='http://pbs.twimg.com/profile_background_images/7904884343728/ab960e4a9bfeb7dd71c91e5b4f5c9dd1.jpeg', profile_link_color='C34242', id_str='44873543411', listed_count=2, notifications=False, following=True, _api=<tweepy.api.API object at 0x000000000327D828>, geo_enabled=False, location='LOCATION', default_profile=False, profile_use_background_image=True, favourites_count=19, profile_sidebar_fill_color='C9C9C9', lang='en', utc_offset=25200, friends_count=232, protected=False, has_extended_profile=False, profile_background_color='07090B', followers_count=2926, created_at=datetime.datetime(20309, 6, 5,3 11, 39, 26), contributors_enabled=False, profile_image_url_https='https://pbs.twimg.com/profile_images/3788003234000505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png', profile_banner_url='https://pbs.twimg.com/profile_banners/44873511/1359873943465', profile_background_tile=True, description='|DSECRIPTION|', profile_text_color='1C1F23', profile_sidebar_border_color='FFFFFF', is_translator=False, entities={'description': {'urls': []}}, is_translation_enabled=False, time_zone=,profile_background_image_url_https='https://pbs.twimg.com/profile_background_images/790488728/ab960e4a9bfeb7dd71c43491e5b4f5c9dd1.jpeg', follow_request_sent=False, name='Xxx Xxx', profile_image_url='http://pbs.twimg.com/profile_images/3788000563400505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png', url=None, default_profile_image=False), sender_screen_name='xxxtnb', sender_id=4487345511, sender_id_str='4487343511', text='kjbkljb', id=715904763565666629443, created_at=datetime.datetime(2016, 4, 1, 14, 12, 51), id_str='715904763565629443', recipient=User(statuses_count=8, verified=False, _json={'default_profile_image': False, 'statuses_count': 8, 'following': False, 'verified': False, 'entities': {'description': {'urls': []}}, 'profile_background_image_url': 'http://pbs.twimg.com/profile_background_images/2424565639181/KOJ.jpg', 'screen_name': 'xxxx', 'is_translation_enabled': False, 'id': 82332348693, 'id_str': '82232348693', 'notifications': False, 'name': 'Yyyyy yyyyy', 'profile_text_color': '0C3E53', 'profile_background_tile': False, 'location': xxxx', 'default_profile': False, 'profile_use_background_image': True, 'profile_sidebar_fill_color': 'FFF7CC', 'lang': 'en', 'protected': False, 'has_extended_profile': False, 'profile_background_color': 'BADxFCD', 'is_translator': False, 'created_at': xxx 2009', 'contributors_enabled': False, 'profile_image_url_https': 'https://pbs.twimg.com/profile_images/1302134054090532/36114_1220026641036_1840037693_409509_786157_n_normal.jpg', 'time_zone':, 'description': DESC.', 'listed_count': 0, 'profile_sidebar_border_color': 'F2E195', 'followers_count': 134, 'favourites_count': 0, 'geo_enabled': False, 'friends_count': 49, 'profile_background_image_url_https': 'https://pbs.twimg.com/profile_background_images/242439134381/KOJ.jpg', 'follow_request_sent': False, 'utc_offset': 19800, 'profile_image_url': 'http://pbs.twimg.com/profile_images/1302134032/36114_1220026641036_341840037693_409509_786157_n_normal.jpg', 'url': None, 'profile_link_color': 'FF0000'}, id=8234834693, screen_name='', profile_background_image_url='http://pbs.twimg.com/profile_background_images/2424343439181/KOJ.jpg', profile_link_color='FF0000', id_str='82348693', listed_count=0, notifications=False, following=False, _api=<tweepy.api.API object at 0x000000000327D828>, geo_enabled=False, location=’x', default_profile=False, profile_use_background_image=True, favourites_count=0, profile_sidebar_fill_color='FFF7CC', lang='en', utc_offset=194800, friends_count=494, protected=False, has_extended_profile=False, profile_background_color='BADFCD', followers_count=144, created_at=datetime.datetime(2009, 10, 14, 12, 36, 46), contributors_enabled=False, profile_image_url_https='https://pbs.twimg.com/profile_images/130213404332/4336114_1220026641036_1840037693_40943509_786157_n_normal.jpg', profile_background_tile=False, description=DESC.', profile_text_color='0C3E53', profile_sidebar_border_color='F2E195', is_translator=False, entities={'description': {'urls': []}}, is_translation_enabled=False, time_zone='’, profile_background_image_url_https='https://pbs.twimg.com/profile_background_images/242434434349181/KOJ.jpg', follow_request_sent=False, name='Yyyyy yyyyy', profile_image_url='http://pbs.twimg.com/profile_images/1302134032/36143414_1220026641036_1840037693_40954309_786157_n_normal.jpg', url=None, default_profile_image=False), recipient_id=8234348693, entities={'user_mentions': [], 'hashtags': [], 'urls': [], 'symbols': []}, 
[DirectMessage(发送方=用户(状态\u计数=8452,验证=False,\u json={'default\u profile\u image':False,'status\u计数':8452,'following':True,'verified':False,'entications':{'description':{'url':[]},'profile\u background\u image\u url':'http://pbs.twimg.com/profile_background_images/7904887943048/ab960e4a9bfeb7dd71c91e5b4f5c9dd1.jpeg“,”屏幕名称“:”xxxtnb“,”是否启用了翻译“:False”,“id”:448743511,“id”str“:”448473511“,”通知“,”False,“名称“:”Xxx Xxx“,”配置文件文本颜色“:”1C1F23“,”配置文件背景“:True,“locati”关于“:”xxxx“,”默认配置文件“:False“,”配置文件使用背景图像“:True“,”配置文件侧栏“,”填充颜色“:”C9C9C9“,”语言“:”en“,”受保护“:False“,”已扩展配置文件“:False“,”配置文件背景颜色“:”07090B“,”是翻译“,”False“,”创建于“:”2009年6月5日11:39:26+0000“,”贡献者“,”已启用“:False“,”配置文件图像url”: 'https://pbs.twimg.com/profile_images/3788000004442443400505954094/26ac579d33b26ee9e6748a3563fe3754dc_normal.png“,”个人资料_横幅_网址“:”https://pbs.twimg.com/profile_banners/44873556411/135934873965“,”时区“:”xxxx“,”描述“:”数据描述“,”列表计数“:2,“配置文件侧边栏边框颜色“:”FFFFFF“,”关注者计数“:296,”网站计数:19,“地理位置启用”:False,“好友计数”:2332,“个人资料、背景、图像、url、https”:https://pbs.twimg.com/profile_background_images/79048873328/ab960e433a9bfeb7dd71c91e5b4f5c9dd1.jpeg“,“跟随请求发送”:False,“utc偏移量”:25200,“配置文件图像url”:”http://pbs.twimg.com/profile_images/378800000324505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png,“url”:无,“配置文件链接颜色”:“C34242”},id=44843473511,屏幕\u name='xxxtnb',配置文件\u背景\u图像\u url='10http://pbs.twimg.com/profile_background_images/7904884343728/ab960e4a9bfeb7dd71c91e5b4f5c9dd1.jpeg,profile_link_color='C34242',id_str='44873543411',列出的_count=2,notifications=False,following=True,_api=,geo_enabled=False,location='location',默认_profile=False,profile_use_background_image=True,favorities_count=19,profile_sidebar_fill_color='C9C9',lang='en',utc_offset=25200,friends_count=232,protected=False,has_extended_profile=False,profile_background_color='07090B',followers_count=2926,创建时间=datetime(20309,6,5,3,11,39,26),contributors\u enabled=False,profile\u image\u url\u https=https://pbs.twimg.com/profile_images/3788003234000505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png“,配置文件_banner_url=”https://pbs.twimg.com/profile_banners/44873511/1359873943465,profile_background_tile=True,description='DSECRIPTION|',profile_text_color='1C1F23',profile_侧边栏顺序_color='FFFFFF',是_translator=False,entities={'description':{'url':[]},是否启用了翻译功能=False,时区=,配置文件\u背景\u图像\u url\u https=https://pbs.twimg.com/profile_background_images/790488728/ab960e4a9bfeb7dd71c43491e5b4f5c9dd1.jpeg“,遵循请求发送=False,名称='Xxx Xxx',配置文件\u图像\u url=”http://pbs.twimg.com/profile_images/3788000563400505954094/26ac579d33b26ee9e6748a33fe3754dc_normal.png”“呃l=None,default_profile_image=False),sender_screen_name='xxxtnb',sender_id=4487345511,sender_id_str='4487343511',text='kjbkljb',id=715904765666629443,创建时间=datetime.datetime(2016,4,1,14,12,51),id_str='7159047656565629443',recipient=User(status_count=8,verified=False,_json)={'default_profile_image':False,'statuses_count':8,'following':False,'verified':False,'entities':{'description':{'url':[]},'profile\u background\u image\u url':'http://pbs.twimg.com/profile_background_images/2424565639181/KOJ.jpg“,”屏幕名称“:”xxxx“,”是否启用了翻译“:False,”,id“:82332348693,”,id“,”str“:”82232348693,”,通知“:False,”,name“:”Yyyyy yyy“,”配置文件文本颜色“:”0C3E53“,”配置文件背景“:False,”,位置“:xxxx“,”默认ofile':False,'profile_use_background_image':True,'profile_sidebar_fill_color':'FFF7CC','lang':'en','protected':False,'has_extended_profile':False,'profile_background__color':'BADxFCD','is_translator':False,'created__at':xxx 2009,'contributors(enabled':False,'https://pbs.twimg.com/profile_images/1302134054090532/36114_1220026641036_1840037693_409509_786157_n_normal.jpg、'时区':,'描述','描述','列表计数':0,'配置文件侧栏(边框)颜色':'F2E195','关注者(计数):134,'收藏夹(计数)0,'地理位置启用':False,'朋友(计数:49,'配置文件(背景)图像(url):'https://pbs.twimg.com/profile_background_images/242439134381/KOJ.jpg,“follow_request_sent”:False,“utc_offset”:19800,“profile_image_url”:http://pbs.twimg.com/profile_images/1302134032/36114_1220026641036_341840037693_409509_786157_n_normal.jpg“,“url”:无,“配置文件链接颜色”:“FF0000”},id=8234834693,屏幕\'u名称='',配置文件\'u背景\'u图像\'u url='http://pbs.twimg.com/profile_background_images/2424343439181/KOJ.jpg'中,配置文件链接颜色为FF0000',id为str为82348693',列出了计数为0,通知为假,跟踪为假,api为假,地理位置为假,位置为x',默认配置文件为假,配置文件使用背景图像为真,收藏夹为真unt=0,profile\u sidebar\u fill\u color='FFF7CC',lang='en',utc\u offset=194800,friends\u count=494,protected=False,has\u extended\u profile=False,profile\u background\u color='BADFCD',followers\u count=144,created\u at=datetime.datetime(2009,10,14,12,36,46),contributors\u enabled=False,profile\u image\u url\u https=https://pbs.twimg.com/profile_images/130213404332/4336114_1220026641036_1840037693_40943509_786157_n_normal.jpg,个人资料(背景)_
api.direct_messages(count=1)[0].text