Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

How do I post to Gwibber from python?

I have tried

import gwibber.utils
foo = gwibber.utils.GwibberPublic()
foo.post("This is a test message")

from https://wiki.ubuntu.com/Quickly/Snippets.

But it doesn't work.

share|improve this question
add comment

1 Answer

You should really be using the GIR based API, here is a more current example:

from gi.repository import Gwibber

s = Gwibber.Service ()
s.send_message ("This is the content to post", None, None, None)

That will post to all accounts that are currently enabled to send. Here are what the parameters for send_message are:

"""
  send_message: Posts a message
  @message: The message to post to Gwibber as a string or None
  @id: The gwibber message id or None
  @action: The action or None (reply, private)
  @account_id: The ID of the account to post from or None
"""

So if you want to only post from a specific account, you can do something like this:

from gi.repository import Gwibber
accounts_service = Gwibber.Accounts.new ()
s = Gwibber.Service ()

accts = accounts_service.list () # A list of Gwibber.Account objects
for acct in accts:
    print "Gwibber ID: %s, Service: %s, Username: %s, Send: %s" % (acct.props.id, acct.props.service, acct.props.username, "True" if acct.props.send_enabled == "1" else "False")
    #add code to check if this is the account you want to post from, like if you want to post from all twitter accounts you would do this
    if acct.props.service == "twitter":
        s.send_message ("Whatever you want to post", None, None, acct.props.id)
share|improve this answer
    
Fair point Ken. I have deleted mine to prevent misleading others. –  jokerdino Jun 19 '12 at 14:46
1  
from gi.repository import Gwibber ImportError: cannot import name Gwibber –  Captain_Glen Jun 19 '12 at 15:59
    
glen@glen-desktop:~/calorie-burner$ locate girepository | grep Gwibber glen@glen-desktop:~/calorie-burner$ –  Captain_Glen Jun 19 '12 at 17:01
    
You need to install gir1.2-gwibber-0.2 –  Ken VanDine Jun 20 '12 at 13:41
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.