$cordovaOauth facebook and googleplus problems

Hello I’m new to ionic and Angular.js. I’m working on my project which will use login via facebook and login via google+. I registered my app in google.developers and also facebook.developers. I set url to: http://localhost/ and redirect_url: http://localhost/callback But in Facebook when i press button “sign in via facebook” got a facebook forms. So I do insert my email and password. But after that I’ve got error and i’m on facebook page. Error:, The page you requested cannot be displayed at the moment. It may be temporarily unvailable, the link you clicked on may be broken or expired or you may not have permission to view this page."

In google+ I can also see forms and after inserting confirm “offline information”, but after that it freeze!

I’m testing app via ionic view on my iphone5.

Here are codes of both $scope.logins();

$scope.facebookLogin = function() {
        $cordovaOauth.facebook("FB_CODE", ["email", "public_profile", "user_friends"]).then(function(result) {
          $state.go('main/dash', {}, {reload: true});
          $scope.access_token = result.access_token;
          //$scope.setCurrentUsername(data.username);
        }, function(error) {
                  var alertPopup = $ionicPopup.alert({
                  title: 'Login failed!',
                  template: 'There was a problem signing in!',
                  buttons:[{
                    type: 'button-assertive',
                    text: 'OK!'
                  }]
                });
        });
  }



$scope.googleLogin = function() {
    $cordovaOauth.google(GOOGLE_PLUS_CODE, ["https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/userinfo.email"]).then(function(result) {
    //console.log("Response Object -> " + JSON.stringify(result));
    $state.go('main/dash', {}, {reload: true});
    }, function(error) {
            var alertPopup = $ionicPopup.alert({
            title: 'Login failed!',
            template: 'There was a problem signing in!',
            buttons:[{
              type: 'button-assertive',
              text: 'OK!'
            }]
          });
        });
  }

Thank you for any helps.
Jamie

Hey @Kraus,

$cordovaOauth does not work with Ionic View, Ionic Serve, Ionic Live-Reload, or PhoneGap Build.

Build your application and install it directly to the device and it should work fine.

Best,

1 Like

Hello @nicraboy Nic. Thank you for your support. Today I try to test app on Samsung galaxy tab 2 and I installed app on device. But error in function statement occurred. So problem with sign in. I think I don’t need Facebook app installed too. But Google+ the same problem.

Thanks for your support once again
Jamie

What is the error that you’re receiving?

Hey!

I think you are looking for this: https://github.com/srameshr/ionic-starter-oauth

Let me know how it went.

Hey, after 2 days I used debugger on ios simulator and fix problem with facebook. InAppBrowser and my ngCordova.js have got a problem with naming. So facebook plugin works correctly. But google+ plugin not working.

First I used this code to get acess_token:

$scope.googleLogin = function() {
        $cordovaOauth.google("CLIENT_ID", ["https://www.googleapis.com/auth/urlshortener", "https://www.googleapis.com/auth/userinfo.email"]).then(function(result, data) {
            console.log(JSON.stringify(result));

            $scope.access_token = result.access_token;
            debugger;

            initGooglePlus();
        }, function(error) {
            console.log(error);
            var alertPopup = $ionicPopup.alert({
                  title: 'Přihlášení selhalo!',
                  template: 'Problém s přihlášením.',
                  buttons:[{
                    type: 'button-assertive',
                    text: 'OK!'
                  }]
                });
        });
    }

But after I need some information to get from google plus, like email, name and avatar.
So next code is here:

var initGooglePlus = function(){
    if($scope.access_token !== "") {
      debugger;
      $http.get("https://www.googleapis.com/auth/plus.login", { params: { access_token: $scope.access_token, fields: "id,name,picture,email", format: "json" }}).then(function(result, data) { 
          debugger;
          var profileData = {
              "id": result.data.id,
              "name": result.data.name,
              "email": result.data.email,
              "avatar": result.data.picture
            }
            $scope.setCurrentUser(profileData);
            $state.go('main.dash', {}, {reload: true});
            debugger;  
            }, function(error) {
                alert("Nastal problém s načtením dat Vašeho profilu.");
                console.log(JSON.stringify(error));
            });
    } else {
            alert("Nepřihlášen.");
            $state.go('login', {}, {reload: true});
        }

  }

The problem is my object ‘result’ has got just a few atributes but no name or email or avatar. just data = “plus.login”

Anybody help?
Thanks Jamie

Sounds like $cordovaOauth is working then. Unfortunately I don’t know the RESTful APIs so I cannot help you there.

Best,

Hi Jamie,

I also came across similar situation, did you found out any solution for this

Regards,
Suhas

This has been resolved. Just needed to study api part from Google.

Thanks

1 Like