代码之家  ›  专栏  ›  技术社区  ›  Bruno Vieira

如何用Tweepy发多行推文?

  •  0
  • Bruno Vieira  · 技术社区  · 9 年前

    我怎么能在推特上发这个。。。

    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')
    

    提前谢谢。

    1 回复  |  直到 9 年前
        1
  •  1
  •   Harshith Thota    9 年前

    调用外部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())