我正在尝试将Facebook登录名添加到我的应用中。我现在在弹出窗口中使用facebook SDK。但是现在我想更改它以通过在同一选项卡中打开的Facebook登录页面登录。我尝试在Facebook中找到针对开发人员dosc的答案,但没有得到。我在JavaScript和vue.js中是一个新手。我主要使用python,但是现在我必须找到答案。 我知道我必须像这样创建href:
window.location.href = 'https://www.facebook.com/v3.1/dialog/oauth?client_id='+app_id_fb+'&redirect_uri='+redirect_uri_fb+'&state='+state_param_fb
但是我不知道将其添加到哪里来更改我的弹出式登录名。 我的social-login.js文件:
function login_redirect(login_data){
var form = document.createElement("form");
form.setAttribute("method", 'POST');
form.setAttribute("action", process_social_login_link);
for(var key in login_data) {
if(login_data.hasOwnProperty(key)) {
var hiddenField = document.createElement("input");
hiddenField.setAttribute("type", "hidden");
hiddenField.setAttribute("name", key);
hiddenField.setAttribute("value", login_data[key]);
form.appendChild(hiddenField);
}
}
document.body.appendChild(form);
form.submit();
}
function fb_login(){
FB.getLoginStatus(function(response) {
if (response.authResponse) {
fb_login_redirect({access_token: response.authResponse.accessToken,
u_id: response.authResponse.userID});
} else {
fb_do_login();
}
});
}
window.fbAsyncInit = function() {
FB.init({
appId : fb_app_id,
status : true, // Check login status
cookie : true,
xfbml : true,
version : 'v3.1'
// version : 'v2.8'
});
FB.AppEvents.logPageView();
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/pl_PL/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
facebook.py
class FacebookProvider(BaseProvider):
graph_url = 'https://graph.facebook.com/%s'
graph_url_oauth = graph_url % 'oauth/%s'
client_id = 'xxxx'
client_secret = 'yyy'
access_token = None
app_access_token = None
def verify_access_token(self, access_token, **kwargs):
grant_type = 'client_credentials'
try:
response = requests.get(self.graph_url_oauth % 'access_token',
params={'client_id': self.client_id,
'client_secret': self.client_secret,
'grant_type': grant_type})
except Exception as err:
raise SocialAuthenticationError('Error while connecting to oauth')
app_access_token = response.json().get('access_token')
if app_access_token is None:
raise SocialAuthenticationError('Error while getting app access token')
else:
self.app_access_token = app_access_token
try:
response = requests.get(self.graph_url % 'debug_token', params={'input_token': access_token,
'access_token': app_access_token})
except Exception as err:
print(err)
raise SocialAuthenticationError('Error in request: ' + err)
response_data = response.json()
if response_data.get('data') is None:
raise SocialAuthenticationError('error while getting token debug')
if response_data['data'].get('app_id') != self.client_id:
raise SocialAuthenticationError('invalid token (app_id)')
self.access_token = access_token
return True
有人可以给我提示如何更改该代码以在同一选项卡而不是弹出窗口中登录吗?我对JS很陌生。