How to use the twitterapi.Api function in TwitterAPI

To help you get started, we’ve selected a few TwitterAPI examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github idan / python-twitter / examples / tweet.py View on Github external
PrintUsageAndExit()
    if o in ("--username"):
      usernameflag = a
    if o in ("--password"):
      passwordflag = a
    if o in ("--encoding"):
      encoding = a
  message = ' '.join(args)
  if not message:
    PrintUsageAndExit()
  rc = TweetRc()
  username = usernameflag or GetUsernameEnv() or rc.GetUsername()
  password = passwordflag or GetPasswordEnv() or rc.GetPassword()
  if not username or not password:
    PrintUsageAndExit()
  api = twitterapi.Api(username=username, password=password, input_encoding=encoding)
  try:
    status = api.PostUpdate(message)
  except UnicodeDecodeError:
    print "Your message could not be encoded.  Perhaps it contains non-ASCII characters? "
    print "Try explicitly specifying the encoding with the  it with the --encoding flag"
    sys.exit(2)
  print "%s just posted: %s" % (status.user.name, status.text)