[frogr] Updated examples.c to the new authentication API



commit e38734f420ccb86ac668112171a63750a4a44231
Author: Mario Sanchez Prada <msanchez igalia com>
Date:   Sun Apr 8 04:42:51 2012 +0200

    Updated examples.c to the new authentication API

 src/examples/Makefile.am |    3 ++-
 src/examples/example.c   |   22 ++++++++++++++++++----
 2 files changed, 20 insertions(+), 5 deletions(-)
---
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index 6c413f9..8538145 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -15,7 +15,8 @@ noinst_PROGRAMS = \
 
 example_CFLAGS = \
 	-I$(top_srcdir)/src \
-	$(GLIB_CFLAGS)
+	$(GLIB_CFLAGS)	    \
+	$(LIBSOUP_CFLAGS)
 
 example_LDADD = \
 	$(top_builddir)/src/flicksoup/libflicksoup.a \
diff --git a/src/examples/example.c b/src/examples/example.c
index 00e5656..1d86cb9 100644
--- a/src/examples/example.c
+++ b/src/examples/example.c
@@ -22,6 +22,7 @@
 #include <glib.h>
 
 #include <flicksoup/flicksoup.h>
+#include <libsoup/soup.h>
 
 #define API_KEY "18861766601de84f0921ce6be729f925"
 #define SHARED_SECRET "6233fbefd85f733a"
@@ -32,9 +33,11 @@ static gchar *uploaded_photo_id = NULL;
 static gchar *created_photoset_id = NULL;
 static gchar *first_group_id = NULL;
 static gchar *test_photo_path = NULL;
+static char buffer[64];
 
 /* Prototypes */
 
+static gchar *encode_uri (const gchar *uri);
 void upload_cb (GObject *object, GAsyncResult *res, gpointer source_func);
 void added_to_group_cb (GObject *object, GAsyncResult *res, gpointer unused);
 void get_groups_cb (GObject *object, GAsyncResult *res, gpointer unused);
@@ -52,6 +55,12 @@ gboolean do_work (gpointer unused);
 
 /* Implementations */
 
+static gchar *
+encode_uri                             (const gchar *uri)
+{
+  return soup_uri_encode (uri, "%!*'();:@&=+$,/?#[] ");
+}
+
 void
 upload_cb                               (GObject      *object,
                                          GAsyncResult *res,
@@ -547,6 +556,7 @@ complete_auth_cb                        (GObject      *object,
 
       g_print ("[complete_auth_cb]::Auth token\n");
       g_print ("[complete_auth_cb]::\ttoken = %s\n", auth_token->token);
+      g_print ("[complete_auth_cb]::\ttoken_secret = %s\n", auth_token->token_secret);
       g_print ("[complete_auth_cb]::\tpermissions = %s\n", auth_token->permissions);
       g_print ("[complete_auth_cb]::\tnsid = %s\n", auth_token->nsid);
       g_print ("[complete_auth_cb]::\tusername = %s\n", auth_token->username);
@@ -580,18 +590,22 @@ get_auth_url_cb                         (GObject      *object,
     }
   else
     {
-      g_print ("[get_auth_url_cb]::Result: %s\n\n",
+      gchar *verifier = NULL;
+
+      g_print ("[get_auth_url_cb]::Result: %s&perms=write\n\n",
                auth_url ? auth_url : "No URL got");
 
       /* Make a pause before continuing */
-      g_print ("Press ENTER to continue (after the authorization)...\n\n");
-      getchar ();
+      g_print ("\nEnter the verification code and press ENTER to continue:");
+      gets(buffer);
+      verifier = encode_uri (buffer);
 
       /* Continue finishing the authorization */
       g_print ("Finishing authorization...\n");
-      fsp_session_complete_auth_async (session, NULL, NULL, complete_auth_cb, NULL);
+      fsp_session_complete_auth_async (session, verifier, NULL, complete_auth_cb, NULL);
 
       g_free (auth_url);
+      g_free (verifier);
     }
 }
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]