FacebookConnect插件与phonegap adobe构建不起作用 [英] FacebookConnect plugin with phonegap adobe build not working

查看:150
本文介绍了FacebookConnect插件与phonegap adobe构建不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想按照这个git / tutorial页面集成FacebookConnect: https://github.com/phonegap-build/FacebookConnect



这是我的adobe build config.xml:

 <?xml version =1.0encoding =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 =KeyboardDisplayRequiresUserActionvalue =true/>
< preference name =SuppressesIncrementalRenderingvalue =false/>
< preference name =UIWebViewBouncevalue =true/>
< preference name =TopActivityIndi​​catorvalue =gray/>
< preference name =EnableLocationvalue =false/>
< preference name =EnableViewportScalevalue =false/>
< preference name =AutoHideSplashScreenvalue =true/>
< preference name =ShowSplashScreenSpinnervalue =true/>
< preference name =MediaPlaybackRequiresUserActionvalue =false/>
< preference name =AllowInlineMediaPlaybackvalue =false/>
< preference name =BackupWebStoragevalue =cloud/>
< preference name =orientationvalue =portrait/>
< preference name =phonegap-versionvalue =2.5.0/>
< content src =index.html/>



< plugins>
< plugin name =Devicevalue =CDVDevice/>
< plugin name =Loggervalue =CDVLogger/>
< plugin name =Compassvalue =CDVLocation/>
< plugin name =Accelerometervalue =CDVAccelerometer/>
< plugin name =Cameravalue =CDVCamera/>
< plugin name =NetworkStatusvalue =CDVConnection/>
< plugin name =Contactsvalue =CDVContacts/>
< plugin name =Debug Consolevalue =CDVDebugConsole/>
< plugin name =Echovalue =CDVEcho/>
< plugin name =Filevalue =CDVFile/>
< plugin name =FileTransfervalue =CDVFileTransfer/>
< plugin name =Geolocationvalue =CDVLocation/>
< plugin name =Notificationvalue =CDVNotification/>
< plugin name =Mediavalue =CDVSound/>
< plugin name =Capturevalue =CDVCapture/>
< plugin name =SplashScreenvalue =CDVSplashScreen/>
< plugin name =Batteryvalue =CDVBattery/>
< plugin name =Globalizationvalue =CDVGlobalization/>
< plugin name =InAppBrowservalue =CDVInAppBrowser/>
< plugin name =com.phonegap.facebook.Connectvalue =com.phonegap.facebook.ConnectPlugin/>
< gap:plugin name =FacebookConnect>
< param name =APP_IDvalue =133914256793487/>
< / gap:plugin>
< / plugins>



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

然后,我添加了简单示例中显示的各种JavaScript剪贴板和按钮: https://github.com/phonegap-build/FacebookConnect/tree/master/example/Simple 包括:

  document.addEventListener('deviceready',function(){
try {
警告('设备准备好!确保你的app_id低于此警报');
FB.init({appId:133914256793487,nativeInterface:CDV.FB,useCachedDialogs:false});
document.getElementById('data')。innerHTML =;
} catch(e){
alert(e);
}
}假);

使用我更新的appid。当我的应用程序加载 - 我得到警报说设备准备好了!



然后我再收到两个警报,一个说:插件在init上失败。
$ b

然后一个说法:auth.status上的插件失败。



我已将我的Android调试密钥库哈希添加到脸书上的应用程序+我的开发者设置



我不知道如何从这里进行调试。



干杯,



Andy

解决方案

我建议您使用inappbrowser插件来做到这一点。示例如下所示。
请填写以下xxx相关信息

  var my_client_id =xxxxxx,//您的APP ID 
my_secret =xxxxxxxxx,//您的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; //我们的KKERPER
var ref; // IN APP BROWSER REFERENCE

// FACEBOOK
var Facebook = {
init:function(){
//开始授权
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;

//通过LINK调用APP BROWSER
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){

//关闭INAPPBROWSER和NAVIGATE TO INDEX
ref.close();

//这是要在服务器端保护客户端秘密
var codeUrl ='https://graph.facebook.com/oauth/access_token?client_id='+my_client_id+ '&安培; client_secret =' + my_secret + '&安培; REDIRECT_URI =' + my_redirect_uri + '&安培;码=' + 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]);
},
错误:function(){
alert(未知错误发生);
}
}) ;
}
}

我将添加更多的注销功能和发布到墙壁等
您可以在不推荐使用者这里找到文档


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

解决方案

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

这篇关于FacebookConnect插件与phonegap adobe构建不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆