FacebookConnect plugin with phonegap adobe build n

2019-04-12 13:56发布

I have a Phonegap projct which is being built with adobe build.

I want to integrate FacebookConnect as per this git / tutorial page : https://github.com/phonegap-build/FacebookConnect

This is my adobe build config.xml :

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns= "http://www.w3.org/ns/widgets" 
xmlns:gap= "http://phonegap.com/ns/1.0" 
id= "com.TomBers.foodidapp" 
version = "0.0.1"> 

<cordova>
    <preference name="KeyboardDisplayRequiresUserAction" value="true" />
    <preference name="SuppressesIncrementalRendering" value="false" />
    <preference name="UIWebViewBounce" value="true" />
    <preference name="TopActivityIndicator" value="gray" />
    <preference name="EnableLocation" value="false" />
    <preference name="EnableViewportScale" value="false" />
    <preference name="AutoHideSplashScreen" value="true" />
    <preference name="ShowSplashScreenSpinner" value="true" />
    <preference name="MediaPlaybackRequiresUserAction" value="false" />
    <preference name="AllowInlineMediaPlayback" value="false" />
    <preference name="BackupWebStorage" value="cloud" />
    <preference name="orientation" value="portrait" />
<preference name="phonegap-version" value="2.5.0" />
    <content src="index.html" />



    <plugins>
        <plugin name="Device" value="CDVDevice" />
        <plugin name="Logger" value="CDVLogger" />
        <plugin name="Compass" value="CDVLocation" />
        <plugin name="Accelerometer" value="CDVAccelerometer" />
        <plugin name="Camera" value="CDVCamera" />
        <plugin name="NetworkStatus" value="CDVConnection" />
        <plugin name="Contacts" value="CDVContacts" />
        <plugin name="Debug Console" value="CDVDebugConsole" />
        <plugin name="Echo" value="CDVEcho" />
        <plugin name="File" value="CDVFile" />
        <plugin name="FileTransfer" value="CDVFileTransfer" />
        <plugin name="Geolocation" value="CDVLocation" />
        <plugin name="Notification" value="CDVNotification" />
        <plugin name="Media" value="CDVSound" />
        <plugin name="Capture" value="CDVCapture" />
        <plugin name="SplashScreen" value="CDVSplashScreen" />
        <plugin name="Battery" value="CDVBattery" />
        <plugin name="Globalization" value="CDVGlobalization" />
        <plugin name="InAppBrowser" value="CDVInAppBrowser" />
        <plugin name="com.phonegap.facebook.Connect" value="com.phonegap.facebook.ConnectPlugin" />
        <gap:plugin name="FacebookConnect">
   <param name="APP_ID" value="133914256793487" />
 </gap:plugin>
    </plugins>



    <access origin="*" />
</cordova>
</widget>

I then added the various javascript scraps and buttons shown in the Simple example : https://github.com/phonegap-build/FacebookConnect/tree/master/example/Simple including :

  document.addEventListener('deviceready', function() {
                                      try {
                                      alert('Device is ready! Make sure you set your app_id below this alert.');
                                      FB.init({ appId: "133914256793487", nativeInterface: CDV.FB, useCachedDialogs: false });
                                      document.getElementById('data').innerHTML = "";
                                      } catch (e) {
                                      alert(e);
                                      }
                                      }, false);

With my updated appid. When my app loads - i get the alert saying device is ready!

Then I get 2 more alerts, one saying : plugin fail on init.

Then one saying : plugin fail on auth.status.

I have added my android debug keystore hash to the app on facebook + my developer settings.

I am not sure how to debug from here.

Cheers,

Andy

2条回答
神经病院院长
2楼-- · 2019-04-12 14:46

I would suggest you use the inappbrowser plugin to do this instead... example shown below. Fill in the xxx below with your relevant info

var my_client_id = "xxxxxx", // YOUR APP ID
    my_secret = "xxxxxxxxx", // YOUR APP SECRET 
    my_redirect_uri = "https://www.facebook.com/connect/login_success.html", // LEAVE THIS
    my_type ="user_agent", my_display = "touch"; // LEAVE THIS

var facebook_token = "fbToken"; // OUR TOKEN KEEPER
var ref; //IN APP BROWSER REFERENCE

// FACEBOOK
var Facebook = {
    init:function(){
         // Begin Authorization
         var authorize_url = "https://www.facebook.com/dialog/oauth?";
         authorize_url += "client_id=" + my_client_id;
         authorize_url += "&redirect_uri=" + my_redirect_uri;
         authorize_url += "&display=" + my_display;
         authorize_url += "&scope=publish_stream";

             //CALL IN APP BROWSER WITH THE LINK
         ref = window.open(authorize_url, '_blank', 'location=no');

         ref.addEventListener('loadstart', function(event){

             Facebook.facebookLocChanged(event.url);

          });

    },
    facebookLocChanged:function(loc){

        if (loc.indexOf("code=") >= 1  ) {

            //CLOSE INAPPBROWSER AND NAVIGATE TO INDEX
            ref.close();

            //THIS IS MEANT TO BE DONE ON SERVER SIDE TO PROTECT CLIENT SECRET
            var codeUrl = 'https://graph.facebook.com/oauth/access_token?client_id='+my_client_id+'&client_secret='+my_secret+'&redirect_uri='+my_redirect_uri+'&code='+loc.split("=")[1];
            console.log('CODE_URL::' + codeUrl);
            $.ajax({
                url: codeUrl,
                data: {},
                type: 'POST',
                async: false,
                cache: false,
                success: function(data, status){
                    //WE STORE THE TOKEN HERE
                    localStorage.setItem(facebook_token, data.split('=')[1].split('&')[0]);
                    },
                error: function(){
                    alert("Unknown error Occured");
                }
            }); 
        }
    }

I would add more functions for logout and posting to a wall etc. You can find documenatation on the inappbrowser here

查看更多
ら.Afraid
3楼-- · 2019-04-12 14:50

After hours and hours of trying I got this to work. Here's what's wrong with the proposed xml:

  • Tag cordova is wrong, remove it.
  • Tag gap:plugin does NOT go inside the plugins tag.
  • Tag plugin name="com.phonegap.facebook.Connect" is unnecessary and probably wrong.

Then I suggest inspecting the .apk file produced by phonegap build. If things are working as they should the files cdv-plugin-fb-connect.js and facebook-js-sdk.js should be present in assets/www. By the way those files must not be present in the supplied src.

查看更多
登录 后发表回答