2

I'm developing a node.js app with Facebook login, I'm trying to do unit and integration tests with mocha. So in a function I have this code in order to login:

exports.loginFacebook = function (done){
request({uri:"https://graph.facebook.com//oauth/access_token?client_id={app-id}&client_secret={app-secret}&grant_type=client_credentials",
    method: "GET",
        timeout: reqOpts.timeout}, 
    function(err, res, body) {
    if(err){
        throw err;
    }
    else{
        uri2 = "https://graph.facebook.com/APP_ID/accounts/test-users?"+String(body);
        request({uri:uri2,
            method: "GET",
                timeout: reqOpts.timeout},
         function(err, res, body) {
            if(err){
                throw err;
            }
            else{
                login_url = JSON.parse(body).data[0].login_url
                console.log(login_url);
                request({uri:login_url,
                    method: "GET",
                    timeout: reqOpts.timeout},
                 function(err, res, body) {
                    if(err){
                        throw err;
                    }
                    else{
                          request('http://localhost:4004/auth/facebook', reqOpts, function(err, res, body2) {
                        //console.log(res.statusCode)
                        //console.log(err)
                        done()  
                      });   
                    }
                }); 
            }
        });
    }
});
};

Basically I call Facebook API to get the access token, then I list my testing users and I finally I login with the first one. Problem: when I call the login_url, Facebook redirects to this webpage: https://i.stack.imgur.com/nsbkG.jpg ("update your browser"), so I'm not able to do a correct login.

Any ideas how to solve this?

thanks!

  • Try setting a User-Agent header in the options you're passing to request. I can't tell what that function actually is, but the docs should say how to set a header. You can use a User-Agent like "Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.2 Safari/537.36", which will convince facebook's servers that the request is from a newish version of chrome. – jjm Jul 09 '13 at 14:39
  • May be the problem is related to http://stackoverflow.com/questions/5308281/facebook-test-accounts-using-selenium-failing-to-log-in-my-fake-users ? – Eljah Jul 28 '13 at 19:29

0 Answers0