UPDATE:
的Facebook登錄 - 混合應用
最後,我結束了通過使用Eclipse apache cordova/phonegap
Android和Xcode中的iOS imlementing。這是我首選設置的唯一解決方案。
鏈接下載插件和文件:https://github.com/phonegap/phonegap-facebook-plugin
Previous post:
我想實現的Facebook登錄到我的混合應用。我已經在Facebook文檔中做了很少的研究,但是我還沒有找到任何可行的方法。如果您可以提供一些提示,那將會非常有幫助。我會獎勵一個可以告訴我如何去做的人。
我不想通過Phonegap/cordova和其他框架,因爲它需要我很多時間來研究這些框架。
Hybrid apps - like native apps, run on the device, and are written with web technologies (HTML5, CSS and JavaScript). Hybrid apps run inside a native container, and leverage the device’s browser engine (but not the browser) to render the HTML and process the JavaScript locally. A web-to-native abstraction layer enables access to device capabilities that are not accessible in Mobile Web applications, such as the accelerometer, camera and local storage.
如果任何人有任何解決方案,並願意提供幫助,請讓我知道。
我試過Javascript SDK,但沒有運氣。
代碼:
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : 'xxxx', // App ID
channelUrl : '//xxxx/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
// Here we subscribe to the auth.authResponseChange JavaScript event. This event is fired
// for any authentication related change, such as login, logout or session refresh. This means that
// whenever someone who was previously logged out tries to log in again, the correct case below
// will be handled.
FB.Event.subscribe('auth.authResponseChange', function(response) {
// Here we specify what we do with the response anytime this event occurs.
if (response.status === 'connected') {
// The response object is returned with a status field that lets the app know the current
// login status of the person. In this case, we're handling the situation where they
// have logged in to the app.
testAPI();
} else if (response.status === 'not_authorized') {
// In this case, the person is logged into Facebook, but not into the app, so we call
// FB.login() to prompt them to do so.
// In real-life usage, you wouldn't want to immediately prompt someone to login
// like this, for two reasons:
// (1) JavaScript created popup windows are blocked by most browsers unless they
// result from direct interaction from people using the app (such as a mouse click)
// (2) it is a bad experience to be continually prompted to login upon page load.
FB.login();
} else {
// In this case, the person is not logged into Facebook, so we call the login()
// function to prompt them to do so. Note that at this stage there is no indication
// of whether they are logged into the app. If they aren't then they'll see the Login
// dialog right after they log in to Facebook.
// The same caveats as above apply to the FB.login() call here.
FB.login();
}
});
};
// Load the SDK asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
/* js.src = "//connect.facebook.net/en_US/all.js"; */
js.src="https://connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
// Here we run a very simple test of the Graph API after login is successful.
// This testAPI() function is only called in those cases.
function testAPI() {
console.log('Welcome! Fetching your information.... ');
FB.api('/me', function(response) {
console.log('Good to see you, ' + response.name + '.');
});
}
</script>
<!--
Below we include the Login Button social plugin. This button uses the JavaScript SDK to
present a graphical Login button that triggers the FB.login() function when clicked.
Learn more about options for the login button plugin:
/docs/reference/plugins/login/ -->
<!-- <fb:login-button show-faces="true" width="200" max-rows="1"></fb:login-button> -->
<!-- End script of Facebook Login -->
的JavaScript SDK應該正常工作在本地,但如果你使用的示例初始化代碼,你會到指定http://或https://而不是文檔中的協議相對'//'示例 – Igy
@Igy - 我用我的代碼更新了我的帖子。問題是,我得到了這個錯誤消息:給定的URL不被應用程序配置允許:一個或多個給定的URL不被應用程序的設置所允許。它必須與網站網址或Canvas網址匹配,或者該網域必須是其中一個應用網域的子網域。我懷疑這是因爲應用程序域和移動網站的網址。但我應該在那裏放?我目前已將手機網站的網址和應用程序域名放入:我的主機服務器名稱,我上傳了頻道文件。 – JunM
@Igy,只有當我使用'localhost'或者我上傳我的HTML文件到我的主機服務器時,我纔得到這個工作。有沒有其他方法?或者我只是錯過了那裏的一個重要的應用程序設置? – JunM