Microblog

Ubuntu Opportunistic Developers Week March 2010 - Microblog from your app with the Gwibber API - Ken VanDine - Mar 2 2010

(01:16:09 PM) kenvandine: ok... only 16 minutes late
(01:16:41 PM) kenvandine: ok, we are here to talk about the Gwibber API
(01:17:08 PM) kenvandine: A quick intro to Gwibber
(01:17:22 PM) kenvandine: Gwibber is a social networking client as well as a desktop service
(01:17:35 PM) kenvandine: that can be used to post messages to a variety of services
(01:17:43 PM) kenvandine: facebook, twitter, identi.ca
(01:17:43 PM) kenvandine: etc
(01:17:53 PM) kenvandine: it can also pull feeds from them, images, etc
(01:18:11 PM) kenvandine: the client is just a frontend to the desktop service that does the real heavy lifting
(01:18:24 PM) kenvandine: the desktop service also provides both dbus and python APIs
(01:18:47 PM) kenvandine: as an application developer, you can embed some social networking features into your application pretty easily
(01:19:10 PM) kenvandine: i have some examples prepared and we can browse through them
(01:19:26 PM) kenvandine: first there are some python docs at http://people.canonical.com/~kenvandine/gwibber/docs/html/
(01:19:46 PM) kenvandine: right now that mostly documents the python api
(01:19:56 PM) kenvandine: we want to generate docs for the DBus API as well
(01:20:10 PM) kenvandine: so if anyone knows how to do that in epydoc, please let me know after the session... :)
(01:20:30 PM) kenvandine: all of the examples are available in bzr at lp:~ken-vandine/+junk/gwibber-api-examples
(01:20:33 PM) kenvandine: bzr branch lp:~ken-vandine/+junk/gwibber-api-examples
(01:20:34 PM) kenvandine: or
(01:20:53 PM) kenvandine: you can get them in the browser as well, i'll provide links as we discuss them
(01:21:06 PM) kenvandine: most common operation would be posting messages of course
(01:21:11 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/send_message.py.txt
(01:21:42 PM) kenvandine: as you can see the api is quite simple
(01:21:52 PM) kenvandine: import gwibber.lib
(01:21:56 PM) kenvandine: gw = gwibber.lib.GwibberPublic()
(01:22:11 PM) kenvandine: GwibberPublic is the class we provide with all the public python methods
(01:22:20 PM) kenvandine: so most of the examples will use this
(01:22:27 PM) kenvandine: gw.SendMessage("This is a message")
(01:22:46 PM) kenvandine: SendMessage takes a single argument as a string
(01:22:52 PM) kenvandine: which is the content of the message to post
(01:23:09 PM) kenvandine: also note, the method names match the DBus method names
(01:23:35 PM) kenvandine: so it should be pretty easy to discover how to do the same thing from a C, mono, vala, etc app
(01:23:40 PM) kenvandine: via dbus
(01:24:09 PM) kenvandine: i should mention gwibber is broken down into two parts, gwibber and gwibber-service
(01:24:23 PM) kenvandine: the service runs independently of any UI
(01:24:39 PM) kenvandine: and is dbus activated, so if it isn't already running it will start up automatically
(01:24:52 PM) kenvandine: so that is sending a message, pretty easy
(01:25:03 PM) kenvandine: there are some other operations you can do as well
(01:25:18 PM) kenvandine: if you want to tell the service to refresh it's feeds
(01:25:22 PM) kenvandine: you can call Refresh
(01:25:30 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/refresh.py.txt
(01:25:39 PM) kenvandine: also very simple API
(01:25:57 PM) kenvandine: no arguments, it just tells the service to go refresh itself
(01:26:20 PM) kenvandine: you might want to do something a little more complex
(01:26:53 PM) kenvandine: like perhaps query accounts that are configured and find specific accounts or services
(01:27:03 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/get_accounts.py.txt
(01:27:38 PM) kenvandine: the GetAccounts method returns json formated string of accounts
(01:28:08 PM) kenvandine: you can then iterate over the accounts and find specific values, one of interest might be "send_enabled"
(01:28:14 PM) kenvandine: or "receive_enabled"
(01:28:30 PM) kenvandine: those tell gwibber which accounts to post to or pull data from
(01:28:55 PM) kenvandine: so back in the SendMessage example, gwibber would post to all accounts that have send_enabled = True
(01:29:14 PM) kenvandine: you may want to find all the accounts that are enabled and display that in your application
(01:29:30 PM) kenvandine: just as an example
(01:29:38 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/get_services.py.txt
(01:29:42 PM) kenvandine: is very similar
(01:29:50 PM) kenvandine: it queries all services known to gwibber
(01:30:07 PM) kenvandine: some of which you might not have accounts setup for
(01:30:40 PM) kenvandine: and if you want to use gwibber to shorten a url, there is a method for that as well
(01:30:41 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/shorten.py.txt
(01:31:24 PM) kenvandine: Shorten takes an argument of a string and returns a shortened string using the user's configured preferred shortening service
(01:31:29 PM) kenvandine: is.gd, tinyurl.com, etc
(01:32:18 PM) kenvandine: these are the basic method provided in GwibberPublic
(01:32:20 PM) kenvandine: any questions so far?
(01:32:49 PM) kenvandine: that was the goal :)
(01:32:56 PM) kenvandine: ok
(01:32:58 PM) kenvandine: moving on
(01:33:18 PM) kenvandine: there is also a gtk widget available that you can embed into your application
(01:33:44 PM) kenvandine: and we hope people will create a variety of useful gtk widgets and contribute those back to gwibber
(01:33:59 PM) kenvandine: making it even easier to make your application social :)
(01:34:06 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/gwibber-widget.py.txt
(01:34:32 PM) kenvandine: i am not going to talk about the part of this that creates the gtk window, etc
(01:34:43 PM) kenvandine: that is just a place holder so you can run the example if you like
(01:34:53 PM) kenvandine: there are just a couple of key lines you need
(01:34:59 PM) kenvandine: from gwibber.lib.gtk import widgets
(01:35:07 PM) kenvandine: that gives you the widgets
(01:35:14 PM) kenvandine: poster = widgets.GwibberPosterVBox()
(01:35:47 PM) kenvandine: GwibberPosterVBox is a VBox that contains a text input, text overlay for character count, send button and toggles for each service
(01:36:55 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/poster.png
(01:37:00 PM) kenvandine: that is what the widget looks like
(01:37:07 PM) kenvandine: so you could embed that into your application
(01:37:20 PM) kenvandine: so
(01:37:24 PM) kenvandine: poster = widgets.GwibberPosterVBox()
(01:37:33 PM) kenvandine: window.add(poster)
(01:37:55 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/gwibber-widget.py.txt
(01:38:08 PM) kenvandine: is really all you need
(01:38:18 PM) kenvandine: let me put up the screenshot again
(01:38:24 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/poster.png
(01:38:34 PM) kenvandine: the toggle buttons on the botton that have the icons for the services
(01:38:45 PM) kenvandine: those are all live and tied into the gwibber service
(01:39:00 PM) kenvandine: so toggling those enables and disables sending to those services desktop wide
(01:39:24 PM) kenvandine: if you are running Lucid, you can see this in action by running gwibber-poster
(01:39:42 PM) kenvandine: another variation there
(01:39:50 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/gwibber-widget-with-contents.py.txt
(01:40:00 PM) kenvandine: this shows adding some default content
(01:40:26 PM) kenvandine: so if your application has some context about what you are going to post about, like perhaps in the rhythmbox example
(01:40:37 PM) kenvandine: you just marked a song you liked, rated it or whatever
(01:41:02 PM) kenvandine: you could have that pre-populate the text input with information about the song you just rated
(01:41:17 PM) kenvandine: and let the user edit the text if they like and hit Send
(01:41:19 PM) kenvandine: to post it
(01:41:42 PM) kenvandine: poster.input.set_text(contents)
(01:41:49 PM) kenvandine: where contents is a string that gets added
(01:42:02 PM) kenvandine: note: if that text STARTS with a url
(01:42:11 PM) kenvandine: it will get shortened automatically
(01:42:34 PM) kenvandine: i don't think that works if the url isn't at the beginning, but i could be wrong
(01:43:06 PM) kenvandine: our hope here is to get lots of application developers to embed this functionality
(01:43:31 PM) kenvandine: really utilize gwibber as a desktop service
(01:43:42 PM) kenvandine: not just as a gui for viewing/posting tweets :)
(01:44:13 PM) kenvandine: i have just one more area i want to touch on, then we can open up some discussion
(01:44:23 PM) kenvandine: gwibber stores all of it's data in desktopcouch
(01:44:35 PM) kenvandine: a very nice document oriented database
(01:45:04 PM) kenvandine: which also has replication features, so your settings can replicate to other computers either directly through desktopcouch or through ubuntu one
(01:45:35 PM) kenvandine: some features of gwibber aren't exposed (at least yet) through the python or dbus APIs
(01:45:43 PM) kenvandine: things like retrieving message contents
(01:45:54 PM) kenvandine: but it is easy to do with desktopcouch directly
(01:45:59 PM) kenvandine: here is an example
(01:46:06 PM) kenvandine: http://people.canonical.com/~kenvandine/gwibber/api-examples/messages_from_couch.py.txt
(01:46:41 PM) kenvandine: this uses the desktopcouch records API to connect to the database and get records
(01:46:49 PM) kenvandine: that match the record_type for gwibber_messages
(01:47:13 PM) kenvandine: results = messages_db.get_records(record_type = record_type, create_view = False)
(01:47:23 PM) kenvandine: results would be a big json string of all your messages
(01:47:34 PM) kenvandine: which you can then iterate over and get individual messages out
(01:47:40 PM) kenvandine: and various bits of data
(01:48:01 PM) kenvandine: your application could also define views for data your app uses regularly
(01:48:14 PM) kenvandine: so perhaps you want to get all the records that have images
(01:48:25 PM) kenvandine: so you could view all your facebook friend's albums
(01:48:35 PM) kenvandine: the data is pretty easy to get at in desktopcouch
(01:48:50 PM) kenvandine: someone just needs to write an extension for f-spot to make it easy to browse them :)
(01:48:54 PM) kenvandine: and maybe even comment
(01:49:19 PM) kenvandine: ok, i think that is all i have
(01:49:25 PM) kenvandine: questions? comments?
(01:49:49 PM) kenvandine: the widget doesn't provide that, but that would be useful
(01:49:54 PM) kenvandine: it is on my todo list :)
(01:50:04 PM) kenvandine: but won't happen for 2.30, we are in feature freeze already
(01:50:13 PM) kenvandine: next?
(01:52:15 PM) kenvandine:  QUESTION: Are the special gtk widgets available in languages other than python? Say I want to use this in an app written in c# and use gtk#? or just plain c?
(01:52:17 PM) kenvandine: not yet
(01:52:36 PM) kenvandine: but for 2.32 (or 3.0, we are following gnome version numbering now)
(01:52:41 PM) kenvandine: i would like to have a libgwibber
(01:52:45 PM) kenvandine: to provide just that
(01:53:11 PM) kenvandine: if there are any C gurus out there and want to help
(01:53:14 PM) kenvandine: please let me know
(01:53:29 PM) kenvandine: ideally we want to move the widgets to C and just create python bindings for it
(01:53:43 PM) kenvandine: QUESTION: how can an user disable an app from using gwibber if that app doesn't have it as a preference? I don't really feel comfortable with random apps being able to send messages out to the public without me having to confirm it first
(01:54:02 PM) kenvandine: hadn't really thought about that
(01:54:20 PM) kenvandine: there isn't really any mechanism for applications register with gwibber to control access
(01:54:54 PM) kenvandine: we'll discuss that next cycle
(01:55:11 PM) kenvandine: well, thanks everyone
(01:55:25 PM) kenvandine: i'll be back for the next session which is showcasing gwibber

MeetingLogs/OpWeek1003/Microblog (last edited 2010-03-02 20:03:41 by pool-71-182-100-128)