eagleoneraptor

WebKit Foursquare authenticate segmentation fault

Jan 7th, 2015
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.09 KB | None | 0 0
  1. #include <gtk/gtk.h>
  2. #include <webkit/webkit.h>
  3.  
  4. void
  5. set_fake_mobile (WebKitWebView *web_view)
  6. {
  7.   WebKitWebSettings *settings;
  8.  
  9.   settings = webkit_web_view_get_settings (web_view);
  10.  
  11.   /* This is based on the HTC Wildfire's user agent. Some
  12.    * providers, like Google, refuse to provide the mobile
  13.    * version of their authentication pages otherwise. eg.,
  14.    * in Google's case, passing btmpl=mobile does not help.
  15.    *
  16.    * The actual user agent used by a HTC Wildfire is:
  17.    * Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; HTC Wildfire
  18.    * Build/FRG83D) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0
  19.    * Mobile Safari/533.1
  20.    *
  21.    * Also note that the user agents of some mobile browsers may
  22.    * not work. eg., Nokia N9.
  23.    */
  24.   g_object_set (G_OBJECT (settings),
  25.                 "user-agent", "Mozilla/5.0 (GNOME; not Android) "
  26.                               "AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile",
  27.                 NULL);
  28. }
  29.  
  30. int
  31. main(int argc, char *argv[])
  32. {
  33.     GtkWidget *main_window;
  34.     GtkWidget *scrolled_window;
  35.     GtkWidget *web_view;
  36.  
  37.     gtk_init (&argc, &argv);
  38.  
  39.     /* Create the widgets */
  40.     main_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  41.     scrolled_window = gtk_scrolled_window_new (NULL, NULL);
  42.     web_view = webkit_web_view_new ();
  43.  
  44.     /* Place the WebKitWebView in the GtkScrolledWindow */
  45.     gtk_container_add (GTK_CONTAINER (scrolled_window), web_view);
  46.     gtk_container_add (GTK_CONTAINER (main_window), scrolled_window);
  47.  
  48.     /* Use mobile user agent */
  49.     set_fake_mobile (WEBKIT_WEB_VIEW (web_view));
  50.  
  51.     /* Open a webpage */
  52.     webkit_web_view_load_uri (WEBKIT_WEB_VIEW (web_view), "https://es.foursquare.com/oauth2/authenticate?response_type=token&client_id=MBNU2NES5HASNDQJ25YPFGG2UGRZHPI3IYTNJGE0KIWT2HCF&redirect_uri=https%3A%2F%2Flocalhost%2F");
  53.  
  54.     /* Show the result */
  55.     g_signal_connect (main_window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
  56.     gtk_window_set_default_size (GTK_WINDOW (main_window), 800, 600);
  57.     gtk_widget_show_all (main_window);
  58.  
  59.     gtk_main ();
  60.  
  61.     return 0;
  62. }
Advertisement
Add Comment
Please, Sign In to add comment