Trying to use openFB with Cordova

So, I have a situation where someone can help.

I am building a mobile APP using PhoneGap Build. I'm trying to use this one http://coenraets.org/blog/2014/04/facebook-phonegap-cordova-without-plugin/

I know correctly if I open the application inBrowser application, it will work. Request permissions, etc. And enter the user data correctly. Of course, I have defined Valid oAuth: localhost / ... html.

So it works for the browser, but doesn't work for mobile. What, if so, should a valid mobile URL be? Because this APP iΒΊm is confused. I don't feel like showing the code, but if so, just ask me.

Developers areaPermissions working fine

Thank;)

0


source to share


2 answers


I have work on a phone.

The weird thing is that no real url is needed, just semantic. I added the Facebook Canvas platform to the facebook app page and filled out the platform form:

URL = http://localhost/www/
Secure Canvas URL = https://localhost/www/

      

Both of the above domains do not exist. I did not fill in the "Valid UAuth redirect URIs" field in the "Advanced" tab.

After that, I wrote the following code in my application:



openFB.init("xyz!@#123456789"
  , "http://localhost/www/oauthcallback.html");

      

It looks like the important thing is that the Facebook Canvas domains or subdomains match one of the openFB.init redirectURL options ...

I am using openFB version 0.1. I will post earlier versions.

UPDATE

It just worked because I was using phonegap serve

, and it makes openFB clear that my app is a website, because the phonegap developer app is a browser shell, not an app shell. If I try to run it in the compiled application ( phonegap local build

) my code doesn't work. I think I'll have to use facebook-connect earlier than I thought ...

+1


source


You can still use openFB and it will work. you don't even need to change anything in the openfb.js file. all you have to do is manipulate the call method from the page you want to call the facebook login window.

let's say for example you have a method to call facebook in index.html then add this script to that index.html page where facebooklogin () function is called

<script>
openFB.init({ appId: 'your-app-id' });
function facebooklogin() {
    openFB.login(function (response) {
        if (response.status === 'connected') {
            if (response.authResponse) {
                var accessToken = response.authResponse.accessToken;
                openFB.api({
                    path: "/{your app version in facebook developer envi.}/me?",
                    params: { "access_token": accessToken, "?fields":"name,email,gender,user_birthday,locale,bio&access_token='"+accessToken+"'" },
                    success: function (response) {
                        var data = JSON.stringify(response);
                       // do whatever you want with the data for example
                       $(".data_div").html(data); 
                       $(".data_email").html(data.email);

                    },
                    error: function(err){
                    alert(err);
                   }
                });
            }
            else { 
                   alert("empty response returned");

            }
        }
        else { 
                alert("not connected");
        }
    },
    {
        scope: "public_profile,email,user_birthday"
    });
}
</script>
      

Run codeHide result




Very important! Please replace {your app version in facebook envi.} With your app version, for example v2.0 or v2.5

also don't forget to change " your app id " for example facebook app 432046826485152

with openfb, you don't have to hack your head over a training hoe to set up a facebook account on other platforms. this will serve all platforms.

0


source







All Articles