Created
January 17, 2009 14:07
-
-
Save greut/48349 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple async call using libsoup on twitter.com | |
// author: Yoan Blanc | |
// compiled using: gcc twitter.c `pkg-config --cflags libsoup-2.4` `pkg-config --libs libsoup-2.4` | |
#include <stdio.h> | |
#include <glib-object.h> | |
#include <libsoup/soup.h> | |
static GMainLoop *main_loop = NULL; | |
void callback (SoupSession *session, SoupMessage *message, gpointer user_data) { | |
printf("called"); | |
gchar *buffer = g_strndup(message->response_body->data, | |
message->response_body->length); | |
printf("%s\n", buffer); | |
printf("length: %d\n", message->response_body->length); | |
g_main_loop_quit(main_loop); | |
} | |
int main () { | |
g_type_init(); | |
g_thread_init(NULL); | |
SoupSession *session = soup_session_async_new(); | |
SoupMessage *message = soup_message_new("GET", "http://twitter.com/statuses/public_timeline.xml"); | |
soup_session_queue_message(session, message, callback, NULL); | |
main_loop = g_main_loop_new(NULL, FALSE); | |
g_main_loop_run(main_loop); | |
g_main_loop_unref(main_loop); | |
return 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env seed | |
// Getting the twitter feed using Seed (via Soup) | |
Seed.import_namespace("GLib"); | |
Seed.import_namespace("Soup"); | |
var base_uri = "http://twitter.com/"; | |
var user = "xxxx"; | |
var password = "xxxx"; | |
function client_auth(session, message, auth, retrying, data) { | |
Seed.print("authenticate as: "+user); | |
auth.authenticate(user, password); | |
} | |
function callback(session, message) { | |
Seed.print("status: "+message.status_code); | |
Seed.print("data: "+message.response_body.data); | |
Seed.print("length: "+message.response_body.length); | |
GLib.main_loop_quit(main); | |
} | |
var session = new Soup.SessionAsync(); | |
var message = new Soup.Message.c_new("GET", base_uri + "statuses/public_timeline.xml"); | |
//var message = new Soup.Message.c_new("GET", base_uri + "statuses/friends_timeline.xml"); | |
session.signal.authenticate.connect(client_auth); | |
session.queue_message(message, callback); | |
var main = GLib.main_loop_new(null, false); | |
GLib.main_loop_run(main); | |
GLib.main_loop_unref(main); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment