如何使用 Tweepy 发送多行推文?
How to tweet multiple lines with Tweepy?
我如何发推文...
List of fruits:
1. Apple
2. Banana
3. Orange
而不是这个?
List of fruits: 1. Apple 2. Banana 3. 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
api.update_status('List of fruits: \n1. Apple \n2. Banana \n3. Orange')
如您所见,使用“\n”无效。 Tweepy 只是忽略了它。
提前致谢。
调用外部API时,不需要在服务器端写Python。所以也许 '\n' 只是作为异常被捕获。或者可能,编码被更改为忽略转义字符。
您可以做的是:
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())
我如何发推文...
List of fruits: 1. Apple 2. Banana 3. Orange
而不是这个?
List of fruits: 1. Apple 2. Banana 3. 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
api.update_status('List of fruits: \n1. Apple \n2. Banana \n3. Orange')
如您所见,使用“\n”无效。 Tweepy 只是忽略了它。
提前致谢。
调用外部API时,不需要在服务器端写Python。所以也许 '\n' 只是作为异常被捕获。或者可能,编码被更改为忽略转义字符。
您可以做的是:
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())