我有一个正在使用adobe build构建的Phonegap项目。
我想根据这个git /教程页面整合FacebookConnect:https://github.com/phonegap-build/FacebookConnect
这是我的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>
然后我添加了简单示例中显示的各种javascript片段和按钮:https://github.com/phonegap-build/FacebookConnect/tree/master/example/Simple包括:
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);
使用我更新的appid。当我的应用程序加载时 - 我收到警告说设备已准备就绪!
然后我再收到2个警报,其中一个说:插件初始化失败。
然后有人说:插件在auth.status上失败。
我已经在facebook +我的开发者设置中将我的android调试密钥库哈希添加到了应用程序。
我不确定如何从这里调试。
干杯,
安迪
答案 0 :(得分:2)
我建议您使用inappbrowser插件代替这样做...示例如下所示。 使用您的相关信息填写下面的xxx
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");
}
});
}
}
我会添加更多功能,以便退出并张贴到墙上等。 您可以在inappbrowser here
上找到文档答案 1 :(得分:0)
经过几个小时的尝试,我得到了这个工作。 这是建议的xml的错误:
然后我建议检查phonegap build生成的.apk文件。如果事情正常,文件cdv-plugin-fb-connect.js和facebook-js-sdk.js应该出现在assets / www中。 顺便说一下,这些文件不能出现在提供的src中。