Notice: The Monaca & Onsen UI Community Forum is shutting down.

For Onsen UI bug reports, feature requests and questions, please use the Onsen UI GitHub issues page. For help with Monaca, please contact Monaca Support Team.

Thank you to all our community for your contributions to the forum. We look forward to hearing from you in the new communication channels.

Facebook login error



  • Hi guys,
    I was looking for the facebook integration

    https://docs.monaca.io/en/sampleapp/samples/facebook/

    But i have an error

    {
    “error”: {
    “message”: “Invalid redirect_uri: N\u00e3o \u00e9 poss\u00edvel carregar a URL”,
    “type”: “OAuthException”,
    “code”: 191,
    “fbtrace_id”: “B9Xhvdff”
    }
    }
    I chose the option website

    0_1468710850441_2016-07-16 (3).png

    0_1468710993004_2016-07-16 (2).png
    Code:

    var app = angular.module('myApp', ['onsen.directives']);
    
    app.controller("ListCtrl", function(){
        this.num = friendsList.length;
        this.friends = friendsList;
    });
    
    app.controller("HomeCtrl", ["$http", function($http){
        this.friendsList={};
        
        ConnectToFB = function(){
            console.log('connect');
            var client_id = 'xxxxxxxx'; //YOUR App ID or API Key
                  var client_secret = 'xxxxxxxxxxx'; //// YOUR App Secret
            var redirect_uri = 'https://www.facebook.com/connect/login_success.html';  //// YOUR CALLBACK URL
            var display = 'touch';
            var authorize_url = "https://graph.facebook.com/v2.0/oauth/authorize?";
            authorize_url += "client_id=" + client_id;
            authorize_url += "&redirect_uri=" + redirect_uri;
            authorize_url += "&display=" + display;
            authorize_url += "&scope=publish_stream,offline_access";
            
             var ref = window.open(authorize_url, '_blank', 'location=yes');
            ref.addEventListener('loadstart', function(event)
            {
                var loc = event.url;
                if(loc.indexOf(redirect_uri + "?") >= 0)
                {
                    ref.close();
                    var result = loc.split("#")[0];
                    var accessToken = result.split("&")[0].split("=")[1];
                    
                    var url = 'https://graph.facebook.com/v2.0/oauth/access_token?';
                        url += 'client_id=' + client_id;
                        url += '&client_secret=' + client_secret;
                        url += '&code=' + accessToken;
                        url += '&redirect_uri=' + redirect_uri;
            
                    $http.post(url,null).success(function(data){
                        accessToken = data.split("&")[0].split("=")[1];
                        url = "https://graph.facebook.com/v2.0/me/taggable_friends?access_token=" + accessToken;
                        $http.get(url).success(function(data){
                            this.friendsList = data.data;
                            ons.navigator.pushPage('list.html',{});
                        });
                    });
                }
            });
        }  
    }]);
    
    
    


  • @Leonardo-Augusto said:

    OAuthException

    Googling the error code shows this:

    In FB App you have to assign an IP Site/ App Domain.

    Facebook matches this url with the url of the request where it came from.
    You can not assign localhost or 127.0.0.1
    You have to enter the IP address your server. Also if it is rails then call the site with your-ip:3000 instead of localhost:3000; I use 192.168.1.154:3000
    Enter the same IP address in IP of the site and APP Domain in your FB APP Settings.

    Edit: Maybe a better answer: http://stackoverflow.com/questions/4691782/facebook-api-error-191