Javascript 如何在移动设备上使用Facebook API?
没有你想象的那么有帮助。我知道我必须在URL的末尾挂起一个显示参数,但我不知道如何调用这样的登录窗口。以下是我现在拥有的:Javascript 如何在移动设备上使用Facebook API?,javascript,facebook,Javascript,Facebook,没有你想象的那么有帮助。我知道我必须在URL的末尾挂起一个显示参数,但我不知道如何调用这样的登录窗口。以下是我现在拥有的: <script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script> <script type="text/javascript"> // initialize the library with the API key FB.
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<script type="text/javascript">
// initialize the library with the API key
FB.init({ apiKey: '{{ facebook_api_key }}', status: true, cookie: true, xfbml: true});
function facebookConnect(form){
function handleResponse(response){
form.submit();
}
FB.login(handleResponse,{perms:'publish_stream,user_about_me,status_update,email,offline_access'});
}
</script>
//使用API密钥初始化库
init({apiKey:'{{facebook_-api_-key}}',状态:true,cookie:true,xfbml:true});
函数facebookConnect(表单){
功能句柄响应(响应){
表单提交();
}
登录(handleResponse,{perms:'publish_stream,user_about_me,status_update,email,offline_access'});
}
这在桌面浏览器中运行良好,但我不知道如何获得对话框的“触摸”或“wap”模式
我正在使用django socialregistration,如果这与此相关的话。为什么要将响应处理程序包装在函数中 做一些类似于:
function handleStatusChange(response) {
if (response.authResponse) {
console.log(response);
}
}
window.fbAsyncInit = function() {
FB.init({ appId: 'YOUR_APP_ID',
status: true,
cookie: true,
xfbml: true,
oauth: true
});
FB.Event.subscribe('auth.statusChange', handleStatusChange);
};
摘自不久前使用触摸对话框登录Facebook时使用的内容,但同样的旧代码似乎不再有效 但是, 您可以将用户重定向到登录URL,facebook将根据平台的不同来完成其余的操作。下面的代码段将登录用户,并重定向回当前页面(如果已设置) 更新:您还需要编辑您的“基本应用程序设置”>“选择您的应用程序与Facebook的集成方式”,并选中“移动网络”以使其正常工作。
window.location = "http://www.facebook.com/dialog/oauth/"
+ "?" + "scope=" + "publish_stream,user_about_me,status_update,email,offline_access"
+ "&" + "client_id=" + YOUR_APP_ID_GOES_HERE
+ "&" + "redirect_uri=" + YOUR_CURRENT_PAGE_URL
+ "&" + "response_type=token";
display:touch属性仍然可以在FB.ui()中使用,如下所示(例如,张贴在墙上):
非常感谢。这对我帮助很大
// Make sure you call FB.init() before FB.ui()
FB.ui({
app_id: YOUR_APP_ID_GOES_HERE,
method: 'feed',
name: "post title",
link: "http://link-to-what-you-are-sharing/",
picture: "your_image.jpg",
description: "post description",
display: 'touch'
},
function callback(r){
if ( (r && r.id) || (r && r.post_id) ){ alert('posted');}
else{ alert('failed'); }
});