2016-10-10 6 views
2

Hi Ich bin ein Anfänger Programmierer versuchen, Facebook Login mit Cordova zu integrieren. Ich folgte diesem ziemlich neuen Leitfaden shown here, und habe Kopie den Code Wort für Wort in ein neues Cordova-Projekt eingefügt. Ich habe Erfahrungen mit Jquery gemacht, aber dies ist das erste Mal, dass ich sowohl angular als auch ionisch begegne.
Hier meine index.htmlFacebook cordova Login-Fehler: 'Konnte das Modul facebookApp wegen .. instanziieren.'

ist
<!DOCTYPE html> 
<html> 
    <head> 
     <meta name="msapplication-tap-highlight" content="no"> 
     <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width"> 
     <title>Facebook Login</title> 

     <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css"> 

     <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> 
     <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 

     <script src="http://code.ionicframework.com/nightly/js/ionic.bundle.js"></script> 
     <script src="https://cdn.rawgit.com/driftyco/ng-cordova/master/dist/ng-cordova.min.js"></script> 
     <script src="https://cdn.rawgit.com/nraboy/ng-cordova-oauth/master/dist/ng-cordova-oauth.min.js"></script> 

     <script type="text/javascript" src="cordova.js"></script> 
     <script type="text/javascript" src="cordova_plugins.js"></script> 
     <!-- added the directories myself below --> 
     <script src="/bower_components/angular/angular.js"></script> 
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
    </head> 
    <body> 
     <div ng-app="facebookApp"> 
      <div ng-controller="mainCtrl"> 
      </div> 
     </div> 

     <div data-role="page" id="home"> 
      <div data-role="header"> 
       <h1>Login</h1> 
      </div> 

      <div data-role="main" class="ui-content"> 
       <p>You need to login to view your Facebook profile information</p> 
       <p>V1.0.1</p> 
       <a target="_blank" href="#" onclick="login()" style="text-decoration: none"><button>Login using Facebook</button></a> 
      </div> 
     </div> 

     <div data-role="page" id="profile"> 
      <div data-role="header"> 
       <a target="_blank" href="#home" class="ui-btn ui-icon-home ui-btn-icon-left">Home</a> 
       <h1>Profile</h1> 
      </div> 
      <div data-role="main" class="ui-content" id="listTable"></div> 
     </div> 

     <script type="text/javascript"> 
      angular.module("facebookApp", ["ionic", "ngCordova"]).controller("mainCtrl", ["$scope", "$cordovaOauth", "$http", function($scope, $cordovaOauth, $http) { 
       window.cordovaOauth = $cordovaOauth; 
       window.http = $http; 
      }]); 

      function login() 
      { 
       facebookLogin(window.cordovaOauth, window.http); 
      } 

      function facebookLogin($cordovaOauth, $http) 
      alert($cordovaOauth); 
      alert($http); 
      { 
       $cordovaOauth.facebook("201821216900862", ["email", "public_profile"], {redirect_uri: "http://localhost/callback"}).then(function(result){ 
        displayData($http, result.access_token); 
       }, function(error){ 
         alert("Error: " + error); 
       }); 
      } 

      function displayData($http, access_token) 
      { 
       $http.get("https://graph.facebook.com/v2.2/me", {params: {access_token: access_token, fields: "name,gender,location,picture", format: "json" }}).then(function(result) { 
        var name = result.data.name; 
        var gender = result.data.gender; 
        var location = result.data.location; 
        var picture = result.data.picture; 
        var html = '<table id="table" data-role="table" data-mode="column" class="ui-responsive"><thead><tr><th>Field</th><th>Info</th></tr></thead><tbody>'; 
        html = html + "<tr><td>" + "Name" + "</td><td>" + name + "</td></tr>"; 
        html = html + "<tr><td>" + "Gender" + "</td><td>" + gender + "</td></tr>"; 
        html = html + "<tr><td>" + "Picture" + "</td><td><img src='" + picture.data.url + "' /></td></tr>"; 
        html = html + "</tbody></table>"; 

        document.getElementById("listTable").innerHTML = html; 
        $.mobile.changePage($("#profile"), "slide", true, true); 
       }, function(error) { 
        alert("There was a problem getting your profile. Check the logs for details."); 
        console.log(error); 
       }); 
      } 
     </script> 
    </body> 
</html> 

Mutliple Fehler von Eclipse zurückgegeben wurde, aber die wichtigsten Fehler zu sein,
Uncaught Error: [$injector:modulerr] Failed to instantiate module facebookApp due to:
und
Error: [$injector:nomod] Module 'facebookApp' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
Anularjs auch eine Webseite für den Fehler erzeugt shown here und vorgeschlagen, dass diese Codezeile: angular.module("facebookApp", ["ionic", "ngCordova"]).controller("mainCtrl", ["$scope", "$cordovaOauth", "$http", function($scope, $cordovaOauth, $http) { die Fehler verursacht. Außerdem ist meine eckige Version 1.5.8, die diese Aktion, die der Code versucht, nicht unterstützt. Die Website schlägt vor, dass ich sie als eine Abhängigkeit zum Top-Level-Modul meiner Anwendung hinzufüge, von dem ich keine Ahnung habe, wie ich es machen soll.

Jede Eingabe oder Ansaugung wird geschätzt, danke! :-)

Antwort

1

Skript Reihenfolge ist sehr wichtig.

Versuchen Sie, sie mögen dieses

<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> 
    <script src="/bower_components/angular/angular.js"></script> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 

    <script src="http://code.ionicframework.com/nightly/js/ionic.bundle.js"></script> 
    <script src="https://cdn.rawgit.com/driftyco/ng-cordova/master/dist/ng-cordova.min.js"></script> 
    <script src="https://cdn.rawgit.com/nraboy/ng-cordova-oauth/master/dist/ng-cordova-oauth.min.js"></script> 

    <script type="text/javascript" src="cordova.js"></script> 
    <script type="text/javascript" src="cordova_plugins.js"></script> 

neu zu ordnen Ist es normal, 2 Angularjs Injektion zu haben?

+0

Hey, der Fehler ist immer noch hier nach dem Re-Arranging und ich habe beide .js selbst hinzugefügt, funktioniert nicht, wenn ich es auch entfernen, immer noch, danke für Ihre Eingabe! –

0

i überwinden dieses Problem so Lösung ist folgendes: -as Sie offen index.php in Chrom Sie wahrscheinlich so etwas wie Fehler sehen:

Error: [$injector:unpr] Unknown provider: $cordovaProvider http://....

, die durch alte Winkelmodulteil verursacht wird - wenn Sie schauen genau auf diesem Teil. Es gibt eine Kopfzeile, die die Teile ionic, ngCordova enthält, aber in der neuen Version ngCordova wurde in zwei Dateien aufgeteilt. Also im Grunde, was Sie tun müssen, ist Winkelkopf dies zu ändern:

angular.module("facebookApp",["ionic","ngCordova","ngCordovaOauth"]).controller("mainCtrl", ["$scope", "$cordovaOauth", "$http"], function($scope, $cordovaOauth, $http) { 
... 
//your app code 
... 
}) 

Beachten ngCordovaOauth wurde hinzugefügt Header. Das war dein Problem. :] Einen schönen Tag noch! Ich hoffe, es hat geholfen, du bist der Erste, dem ich je auf Stackowerflow geholfen habe.

Verwandte Themen