Cap*_*len 6 gwibber quickly application-development
如何从 python 发布到 Gwibber?
我试过了
import gwibber.utils
foo = gwibber.utils.GwibberPublic()
foo.post("This is a test message")
Run Code Online (Sandbox Code Playgroud)
来自https://wiki.ubuntu.com/Quickly/Snippets。
但它不起作用。
您确实应该使用基于 GIR 的 API,这是一个更当前的示例:
from gi.repository import Gwibber
s = Gwibber.Service ()
s.send_message ("This is the content to post", None, None, None)
Run Code Online (Sandbox Code Playgroud)
这将发布到当前启用发送的所有帐户。以下是 send_message 的参数:
"""
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
"""
Run Code Online (Sandbox Code Playgroud)
因此,如果您只想从特定帐户发帖,您可以执行以下操作:
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)
Run Code Online (Sandbox Code Playgroud)