我需要做些什么才能允许手机外部站点和facebook选项卡应用程序之间的异步登录/认证(权限)。
实际上,我需要一个兼具桌面/移动功能的系统。
示例
案例1(移动/外部访问)-登录使用Javascript登录,运行良好的应用程序完美。-它的工作方式,它应该是伟大的!
案例2(Facebook应用程序)-登录并通过PHP获得权限,用户显然已经登录了。我的问题是javascript知道用户已经登录,但仍然要求用户登录他们已经授予的权限。
TLDR:为什么Javascript不能从PHP中获取Auth并识别用户拥有来自PHP的正确权限?当用户通过移动或外部登录到应用程序时,这个登录流是很好的。我已经试过了,它们很好,只是不能一起工作。
我已经看到它的工作方式相反,但我只想要JS或PHP>JS,而不是JS>PHP。
*编辑
window.fbAsyncInit = function()
{
FB.init({
appId : 'APP_ID_HERE', // App ID
channelUrl : '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
oauth : true // enable OAuth 2.0
});我的登入/注销和喜欢的事件处理程序在这里。
(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";
ref.parentNode.insertBefore(js, ref);
}
(document));
function fblogin()
{
FB.login(function(response)
{
},
{ scope: 'email, user_likes' }
);
}
function createRequestObject() {
var obj;
var browser = navigator.appName;
if(browser == "Microsoft Internet Explorer")
{
obj = new ActiveXObject("Microsoft.XMLHTTP");
}
else
{
obj = new XMLHttpRequest();
}
return obj;
}用于移动/桌面的登录非常有效--它可以选择范围,但是当我使用下面的代码设置选项卡应用程序时,权限不会转移到javascript会话。
PHP代码(起作用):
<?php
require_once 'src/facebook.php'; // get facebook sdk
$facebook = new Facebook(array(
'appId' => 'APP ID HERE',
'secret' => 'APP SECRET HERE'
));
$user = $facebook->getUser();
$location = "". $facebook->getLoginUrl(array('scope' => 'email, user_likes'));
// check if we have valid user
if ($user) {
try {
// Proceed knowing you have a logged in user who's authenticated.
$permissions = $facebook->api('/me/permissions', 'get', array('access_token'=>$access_token));
} catch (FacebookApiException $e) {
$fb_user_id = NULL;
// seems we don't have enough permissions
// we use javascript to redirect user instead of header() due to Facebook bug
print '<script language="javascript" type="text/javascript"> top.location.href="' . $location .'"; </script>';
// kill the code so nothing else will happen before user gives us permissions
echo $e->getMessage();
die();
}
} else {
// seems our user hasn't logged in, redirect user to a FB login page
print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';
// kill the code so nothing else will happen before user gives us permissions
die();
}
// at this point we have an logged in user who has given permissions to our APP
// Facebook opens canvas page (which is the mobile/external page) but doesn't transfer permissions.PHP工作得很好,它通过登录/相似按钮将用户传输到移动(画布)页面。如何让PHP将烫伤传递到我的移动/桌面站点所在的画布上?
*编辑2: HTML/PHP:
<div class="container">
<div id="fb-root"></div>
<div id="facebook-div">
<fb:login-button autologoutlink="true" scope="email,user_likes" size="large"></fb:login-button>
<div id="facebook-right" class="fb-like" data-href="https://www.facebook.com/154456204613952" data-width="90" data-layout="button_count" data-show-faces="false" data-send="false"></div>
</div>
//Rest of the code here发布于 2013-10-14 13:34:55
想办法解决这个问题,谢谢你的帮助!在PHP实例化之后,在对用户进行身份验证之后,我没有包含画布php文件.几个月来我一直在努力解决这个问题!此身份验证将传递给Javascript,Javascript处理一切!
这意味着PHP和Javascript调用都能够在同一个应用程序中工作。
https://stackoverflow.com/questions/19322525
复制相似问题