2016-04-19 3 views
1

現在、Ionicハイブリッドアプリケーションを構築中です。Inappbrowserからのデータの取得

残念ながら、私はFacebookのサインアッププロセス中にリクエストの応答データにアクセスすることができません。

Inappbrowserからデータを取得し、コールバックのためにCordovaのIn AppBrowserを使用します。残念ながら私たちはできません。これを達成する最良の方法は何ですか?

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')); 
    } 
} 

答えて

2

私はFacebookではなくプラグインOauthです。このプラグインは、InAppBrowser: "https://github.com/nraboy/ng-cordova-oauth/blob/master/README.md"を使用します。使い方はとても簡単です。

$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 **/ 
      } 
関連する問題