2016-07-13 11 views
3

私はこのtutorialをフォローして、自分のIonicアプリのGoogleログインを作成しています。私はすでに電子メール/パスのログインセットを用意しており、このシステムにGoogleログインを追加したいと考えています。私はログアウトとサービスの部分を除いて指示に従いました。私はすでにメール/パススルーログインのためのいくつかのコードを用意しているので、面倒なところです。Ionicアプリ:既存のバックエンドとGoogleログインを統合する

今のところログイン画面でログインボタンをクリックしても何も起こりません。

そして、私はこの記事のfacebookバージョンで同じ問題があります。

助けてください!

答えて

0

私は同じ問題を抱えており、別のパスに従っています。まず、https://www.thepolyglotdeveloper.com/2014/07/using-oauth-2-0-service-ionicframework/を読んでください。このリンクには、Google Developer Consoleに関する重要な情報があります。そこにあなたのionicアプリを "登録"し、あなたのclientIdとclientSecretを取得しなければなりません。私の実装では、cordovaOauthは必須ですが、ngCordovaが付属しています。

だから私のために動作するコードは次のとおりです。

//ビュー

<button ng-click="googleLogin()" class="button button-block button-stable"> 
     Sign In 
</button> 

//コントローラ

//あなたは、GoogleのデベロッパーコンソールからのclientIdを取るノート

.controller('LoginController', ['$scope', '$cordovaOauth',  
'$http','$location','$rootScope','$state','$window','$ionicLoading', 
function($scope, $cordovaOauth, $http, $location, 
$rootScope,$state,$window,$ionicLoading){ 

    $scope.googleLogin = function(){ 
    $cordovaOauth.google(clientId,   


["https://www.googleapis.com/auth/urlshortener","https://www.googleapis.com/auth/userinfo.email", 

    "https://www.googleapis.com/auth/userinfo.profile", "https://www.googleapis.com/auth/plus.me"]). 
    then(function(result){ 

    var accessToken; 

    accessToken = JSON.stringify(result); 


    $ionicLoading.show({ 
    content: 'Loading', 
    animation: 'fade-in', 
    showBackdrop: true, 
    maxWidth: 200, 
    showDelay: 0 
    }); 
    $http({method:"GET", url:"https://www.googleapis.com/plus/v1/people/me?access_token="+result.access_token}). 
    success(function(response){ 
      var param = { 
      provider: 'google', 
       google: { 
          uid: response["id"], 
          provider: 'google', 
          first_name: response["name"]["givenName"], 
          last_name: response["name"]["familyName"], 
          email: response.emails[0]["value"], 
          image: response.image.url 
         } 
      }; 


      //alert("get method"); 

      first_name = response["name"]["givenName"]; 
      email =response.emails[0]["value"]; 

      $scope.first_name = first_name; 
      $scope.email = email; 


      $ionicLoading.hide(); 

      $location.url('/app/viewyouwanttoredirect'); 

    }, function(error) { 
    alert("App can't get your info: " +error); 
    }); 


}, function(error){ 
    alert("Authentication error!Please try again!" +error); 
    }); 
} 

}]) 

更新: oauthに問題がある場合は、「見つかりませんでしたAppBrowser plugin "の場合、ng-cordova.jsにある は、org.apache.cordova.inappbrowserのすべてのコードをcordova-plugin-inappbrowserに置き換えます。これで問題は解決します。もちろん、あなたがindex.htmlの中に持っている必要があります。

<script src="yourpath/ng-cordova.js"></script> 

あなたはngCordovaOAuthソリューションを望んでいないと言うが、gloginは痛みが付属しています。だから私は私の答えを掲示し、私はあなただけでなく、コミュニティを願っています。

関連する問題