methuselah
methuselah

Reputation: 13216

Retrieving data from an inappbrowser

I am currently building an Ionic hybrid application.

Unfortunately, I am having difficulties accessing the response data of the request during the Facebook sign-up process.

We want to retrieve data from an inappbrowser and are using Cordova's inappbrowser for a callback. Unfortunately we can't. What is the best way of accomplishing this?

function InAppBrowser($scope, $cordovaInAppBrowser, $rootScope, $http, $window) {

    var durr;

    $scope.facebook = facebook;
    $scope.foobar = foobar;

    function facebook() {

        var options = {
            location: 'no',
            clearcache: 'yes',
            toolbar: 'no'
        };

        durr = $cordovaInAppBrowser.open('https://www.facebook.com/dialog/oauth?scope=email,public_profile,user_friends,user_likes,user_photos,user_posts&client_id={client_id}&redirect_uri={callback_url}', '_blank', options)
        .then(function(e) {
            console.log(e);
        })
        .catch(function(e) {
            console.log(e);
        });

        $rootScope.$on('$cordovaInAppBrowser:loadstop', function(e, event) {
            $cordovaInAppBrowser.executeScript(
            { code: "localStorage.setItem('hurr', document.body.innerHTML)" },    
            function(data) {
                console.log(data);
            });
        });
    }

    function foobar() {
        console.log(durr);
        // console.log(durr.localStorage.getItem('hurr'));
    }
}

Upvotes: 3

Views: 1708

Answers (1)

Malo Degachi
Malo Degachi

Reputation: 179

I don't use this for Facebook but the plugin Oauth. This plugin uses InAppBrowser : " https://github.com/nraboy/ng-cordova-oauth/blob/master/README.md ". It's very simple to use.

$cordovaOauth.facebook("Your client id", "scope", "options").then(function (result) {
          Console.log(JSON.stringify(result);
          // Get the information about the user's account
          // See more at https://developers.facebook.com/docs/graph-api/reference/v2.2/user
          $http.get("https://graph.facebook.com/v2.2/me", {
            params: {
              access_token: "your token",
              fields: "id,last_name,first_name,gender,picture,birthday,location,email",
              format: "json"
            }
          }).then(function (result) {
            /** your code **/
          }

Upvotes: 3

Related Questions