将gmail与ionic 3集成时遇到问题,出现运行时错误>> Object(…)不是函数

问题描述 投票:3回答:2

我正在与离子3我试图通过firebasegoogle plus login集成到我的应用程序中的地方。但我收到错误消息,

错误是>>

 ERROR TypeError: Object(...) is not a function
    at GooglePlus.login (index.js:27)
    at HomePage.webpackJsonp.186.HomePage.login (home.ts:28)
    at Object.eval [as handleEvent] (HomePage.html:3)
    at handleEvent (core.js:13589)
    at callWithDebugContext (core.js:15098)
    at Object.debugHandleEvent [as handleEvent] (core.js:14685)
    at dispatchEvent (core.js:10004)
    at core.js:10629
    at HTMLButtonElement.<anonymous> (platform-browser.js:2628)
    at t.invokeTask (polyfills.js:3)


I am putting code below which I have used for integrationg google plus  Integration 

。ts文件

import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { GooglePlus } from '@ionic-native/google-plus/ngx';
import firebase from 'firebase';

/**
 * Generated class for the HomePage page.
 *
 * See https://ionicframework.com/docs/components/#navigation for more info on
 * Ionic pages and navigation.
 */

@IonicPage()
@Component({
  selector: 'page-home',
  templateUrl: 'home.html',
})
export class HomePage {

  constructor(public navCtrl: NavController, public navParams: NavParams  ,private googleplus: GooglePlus ) {
  }

  ionViewDidLoad() {
    console.log('ionViewDidLoad HomePage');
  }

  login(){
      this.googleplus.login({

        'webClientId':"556482052199-f7848gi58u5h89lf2fvs99h5prk2vlbe.apps.googleusercontent.com",
        'offline':true

      }).then(res =>{
        firebase.auth().signInWithCredential(firebase.auth.GoogleAuthProvider.credential(res.idToken)).then(suc=>{
          alert('login successful');
        }).catch(ns=> {
          alert('not successful');
        })
      })
  }



}

。html代码

<button style='    margin: 30px;
padding: 19px;
background: tomato;' ion-buttons icon-left (click)='login()' block outline><ion-icon name="logo-googleplus"> Login with google </ion-icon></button>

**** Package.json ****

{
  "name": "login",
  "version": "0.0.1",
  "author": "Ionic Framework",
  "homepage": "http://ionicframework.com/",
  "private": true,
  "scripts": {
    "start": "ionic-app-scripts serve",
    "clean": "ionic-app-scripts clean",
    "build": "ionic-app-scripts build",
    "lint": "ionic-app-scripts lint"
  },
  "dependencies": {
    "@angular/animations": "5.2.11",
    "@angular/common": "5.2.11",
    "@angular/compiler": "5.2.11",
    "@angular/compiler-cli": "5.2.11",
    "@angular/core": "5.2.11",
    "@angular/fire": "^5.1.1",
    "@angular/forms": "5.2.11",
    "@angular/http": "5.2.11",
    "@angular/platform-browser": "5.2.11",
    "@angular/platform-browser-dynamic": "5.2.11",
    "@ionic-native/core": "^3.6.1",
    "@ionic-native/google-plus": "^5.0.0",
    "@ionic-native/splash-screen": "~4.18.0",
    "@ionic-native/status-bar": "~4.18.0",
    "@ionic/storage": "2.2.0",
    "angularfire2": "^5.1.1",
    "cordova-android": "7.1.4",
    "cordova-plugin-device": "^2.0.2",
    "cordova-plugin-googleplus": "7.0.0",
    "cordova-plugin-ionic-keyboard": "^2.1.3",
    "cordova-plugin-ionic-webview": "^3.1.1",
    "cordova-plugin-splashscreen": "^5.0.2",
    "cordova-plugin-statusbar": "^2.4.2",
    "cordova-plugin-whitelist": "^1.3.3",
    "firebase": "^5.8.2",
    "ionic-angular": "3.9.2",
    "ionicons": "3.0.0",
    "rxjs": "5.5.11",
    "sw-toolbox": "3.6.0",
    "zone.js": "0.8.29"
  },
  "devDependencies": {
    "@ionic/app-scripts": "3.2.1",
    "typescript": "~2.6.2"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-plugin-googleplus": {
        "REVERSED_CLIENT_ID": ".com.googleusercontent.apps.556482052199-f7848gi58u5h89lf2fvs99h5prk2vlbe"
      },
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-device": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-ionic-keyboard": {}
    },
    "platforms": [
      "android"
    ]
  }
}

有关更多信息,我已关注youtube教程1.带有Firebase的Google Authentication Ionic 2和3-最简单的Google身份验证方法https://www.youtube.com/watch?v=g_UGNO3IfN8

  1. http://edupala.com/ionic-3-gmail-login-with-firebase/

但是我每次都会遇到相同的错误错误>>错误TypeError:Object(...)不是一个函数

angular ionic-framework ionic2 ionic3 angularfire2
2个回答
5
投票

正如您提到的,您正在开发ionic版本3项目,并且您正在使用ngx,它清楚显示了最新版本ionic V4的依赖性。

首先删除现有插件离子cordova插件删除cordova-plugin-googleplus --variable REVERSED_CLIENT_ID = myreversedclientid

使用]重新添加>

$ ionic cordova plugin add cordova-plugin-googleplus --variable REVERSED_CLIENT_ID=myreversedclientid

$ npm install --save @ionic-native/google-plus@4

请记住遵循doc v3进行进一步的实现

https://ionicframework.com/docs/v3/native/google-plus/

不要忘记从Firebase控制台启用Google登录方法

https://console.firebase.google.com/project/nakelasi/authentication/providers


3
投票

如果您为项目类型安装了错误的本机插件版本,则会出现此错误。

© www.soinside.com 2019 - 2024. All rights reserved.