简体   繁体   English

如何用Tweepy鸣叫多行?

[英]How to tweet multiple lines with Tweepy?

How can I tweet this... 我该怎么发推文...

List of fruits:
1. Apple
2. Banana
3. Orange

Instead of this? 代替这个?

List of fruits: 1. Apple 2. Banana 3. Orange

My code so far: 到目前为止,我的代码:

import tweepy

# Authenticate connection
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token_key, token_secret)

# Start API
api = tweepy.API(auth)

# Update status
api.update_status('List of fruits: \n1. Apple \n2. Banana \n3. Orange')

As you can see, using '\\n' didn't work. 如您所见,使用'\\ n'无效。 Tweepy just ignored it. Tweepy只是忽略了它。

Thanks in advance. 提前致谢。

When you call an external API, it need not be written in Python on the server end. 调用外部API时,无需在服务器端用Python编写。 So maybe the '\\n' is simply being caught as an exception. 因此,也许只是\\ n被捕获为例外。 Or probably, the encoding is changed to ignore the escape characters. 或者可能是更改了编码以忽略转义字符。

What you can do is: 您可以做的是:

with open('temp.txt', 'w') as f:
   f.write('List of fruits: \n1. Apple \n2. Banana \n3. Orange')

import tweepy

# Authenticate connection
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(token_key, token_secret)

# Start API
api = tweepy.API(auth)

# Update status
with open('temp.txt','r') as f:
   api.update_status(f.read())

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM