diff options
author | Ross Burton <ross@linux.intel.com> | 2008-09-18 21:18:23 +0100 |
---|---|---|
committer | Ross Burton <ross@linux.intel.com> | 2008-09-18 21:18:23 +0100 |
commit | 095846f59988a42b9937053001bebb3368fe22fc (patch) | |
tree | a9fa88cfcb00d7cc8fd31485e5425c2df31f4135 /examples/test-oauth.c | |
parent | 9f77edf5cd7b1dfdb9b2603db15db3be5ce67af0 (diff) | |
download | librest-095846f59988a42b9937053001bebb3368fe22fc.tar.gz |
Add test-oauth
Diffstat (limited to 'examples/test-oauth.c')
-rw-r--r-- | examples/test-oauth.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/examples/test-oauth.c b/examples/test-oauth.c new file mode 100644 index 0000000..b89c52b --- /dev/null +++ b/examples/test-oauth.c @@ -0,0 +1,55 @@ +#include <rest/oauth-proxy.h> +#include <stdio.h> + +static GMainLoop *loop; + +int +main (int argc, char **argv) +{ + RestProxy *proxy; + RestProxyCall *call; + GError *error = NULL; + + g_thread_init (NULL); + g_type_init (); + + loop = g_main_loop_new (NULL, TRUE); + + /* Create the proxy */ + proxy = oauth_proxy_new ( + /* Consumer Key */ + "NmUm6hxQ9a4u", + /* Consumer Secret */ + "t4FM7LiUeD4RBwKSPa6ichKPDh5Jx4kt", + /* FireEagle endpoint, which we bind as required */ + "https://fireeagle.yahooapis.com/%s", TRUE); + + /* First stage authentication, this gets a request token */ + oauth_proxy_auth_step (OAUTH_PROXY (proxy), "oauth/request_token"); + + /* From the token construct a URL for the user to visit */ + g_print ("Go to https://fireeagle.yahoo.net/oauth/authorize?oauth_token=%s then hit any key\n", + oauth_proxy_get_token (OAUTH_PROXY (proxy))); + getchar (); + + /* Second stage authentication, this gets an access token */ + oauth_proxy_auth_step (OAUTH_PROXY (proxy), "oauth/access_token"); + + /* We're now authenticated */ + g_print ("Got access token\n"); + + /* Get the user's current location */ + rest_proxy_bind (proxy, "api/0.1/user"); + call = rest_proxy_new_call (proxy); + + if (!rest_proxy_call_run (call, NULL, &error)) + g_error ("Cannot make call: %s", error->message); + + g_print ("%s\n", rest_proxy_call_get_payload (call)); + + g_object_unref (call); + + g_object_unref (proxy); + + return 0; +} |