Appcelerator : Android 回调登录 facebook 不工作
Appcelerator : Android callback login facebook does not work
在我的应用程序中,在 appcelerator with titanium 上,我尝试使用 facebook 登录但回调不起作用,这是我的代码:
var FB = require('facebook');
FB.forceDialogAuth = true;
FB.initialize();
FB.permissions = [
'public_profile',
'user_friends',
'user_about_me',
'email',
'user_birthday',
'user_hometown',
'user_likes',
'user_location'
];
UserManager.loginWithFb(function(){
checkProfile();
});
在用户管理器中
exports.UserManager.prototype.loginWithFb = function(callback) {
function facebookLogin(e) {
console.log('facebook function');
if (e.success) {
UserManager.getUser(function(user){
FB.removeEventListener('login', facebookLogin);
callback();
});
}
else if (e.error) {
console.log(e.error);
}
}
console.log('loginWithFb');
FB.addEventListener('login', facebookLogin);
FB.authorize();
console.log('FB next');
};
它在 iOs 上完美运行,但在 Android 上运行不佳。
我的 tiapp.xml 就像:
<manifest>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:theme="@style/Theme.AppCompat.NoTitleBar">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="AppName"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
/>
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyC-v_Vk5Y_bPlYi4s1M76KFhp81aua1EcA"/>
</application>
</manifest>
我没有错误只是控制台日志状态:
- 'loginWithFb'
- 'FB next'
我不明白,我阅读了文档,在 Android.
上使用 facebook 登录的方式相同
如果有人能帮我解决这个问题
尝试以下步骤:
1- 删除这个:
FB.forceDialogAuth = true;
2。像这样重新洗牌这些行:
FB.permissions = [
'public_profile',
'user_friends',
'user_about_me',
'email',
'user_birthday',
'user_hometown',
'user_likes',
'user_location'
];
FB.initialize();
必须在设置权限后调用初始化。
最后,在调用 authorize() 之前,您需要像这样在 Android 上设置 proxy worker:
3- 添加window代理到fb实例:
$.yourWindow.fbProxy = fb.createActivityWorker({lifecycleContainer: $.yourWindow});
我试过你的解决方案,结果总是一样。
这是我的控制台日志:
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
[WARN] : chromium: [WARNING:spdy_session.cc(2527)] Received WINDOW_UPDATE for invalid stream 21
[INFO] : loginWithFb
[INFO] : FB next
[WARN] : AwContents: onDetachedFromWindow called when already detached. Ignoring
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
[WARN] : chromium: [WARNING:keycode_converter.cc(91)] empty code string
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
[WARN] : IInputConnectionWrapper: getSelectedText on inactive InputConnection
[WARN] : IInputConnectionWrapper: requestCursorAnchorInfo on inactive InputConnection
[WARN] : IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
[WARN] : chromium: [WARNING:keycode_converter.cc(91)] empty code string
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
如果我的视图是这样创建的,有问题吗:
//-- SLIDE 4
var slide_04 = Ti.UI.createView({
width:'100%',
height:'100%',
backgroundColor:'#44BBA4'
});
var label_04 = Ti.UI.createLabel({
text:"Slide 4",
color:'#222',
textAlign:'center',
font: {
fontSize:24
},
touchEnabled:false
});
slide_04.add(label_04);
scrollableDemo.addView(slide_04);
slide_04.fbProxy = FB.createActivityWorker({lifecycleContainer: slide_04});
在我的应用程序中,在 appcelerator with titanium 上,我尝试使用 facebook 登录但回调不起作用,这是我的代码:
var FB = require('facebook');
FB.forceDialogAuth = true;
FB.initialize();
FB.permissions = [
'public_profile',
'user_friends',
'user_about_me',
'email',
'user_birthday',
'user_hometown',
'user_likes',
'user_location'
];
UserManager.loginWithFb(function(){
checkProfile();
});
在用户管理器中
exports.UserManager.prototype.loginWithFb = function(callback) {
function facebookLogin(e) {
console.log('facebook function');
if (e.success) {
UserManager.getUser(function(user){
FB.removeEventListener('login', facebookLogin);
callback();
});
}
else if (e.error) {
console.log(e.error);
}
}
console.log('loginWithFb');
FB.addEventListener('login', facebookLogin);
FB.authorize();
console.log('FB next');
};
它在 iOs 上完美运行,但在 Android 上运行不佳。
我的 tiapp.xml 就像:
<manifest>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application android:theme="@style/Theme.AppCompat.NoTitleBar">
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<activity
android:name="com.facebook.FacebookActivity"
android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="AppName"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
/>
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyC-v_Vk5Y_bPlYi4s1M76KFhp81aua1EcA"/>
</application>
</manifest>
我没有错误只是控制台日志状态: - 'loginWithFb' - 'FB next'
我不明白,我阅读了文档,在 Android.
上使用 facebook 登录的方式相同如果有人能帮我解决这个问题
尝试以下步骤:
1- 删除这个:
FB.forceDialogAuth = true;
2。像这样重新洗牌这些行:
FB.permissions = [
'public_profile',
'user_friends',
'user_about_me',
'email',
'user_birthday',
'user_hometown',
'user_likes',
'user_location'
];
FB.initialize();
必须在设置权限后调用初始化。 最后,在调用 authorize() 之前,您需要像这样在 Android 上设置 proxy worker:
3- 添加window代理到fb实例:
$.yourWindow.fbProxy = fb.createActivityWorker({lifecycleContainer: $.yourWindow});
我试过你的解决方案,结果总是一样。
这是我的控制台日志:
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
[WARN] : chromium: [WARNING:spdy_session.cc(2527)] Received WINDOW_UPDATE for invalid stream 21
[INFO] : loginWithFb
[INFO] : FB next
[WARN] : AwContents: onDetachedFromWindow called when already detached. Ignoring
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
[WARN] : chromium: [WARNING:keycode_converter.cc(91)] empty code string
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
[WARN] : IInputConnectionWrapper: getSelectedText on inactive InputConnection
[WARN] : IInputConnectionWrapper: requestCursorAnchorInfo on inactive InputConnection
[WARN] : IInputConnectionWrapper: getTextBeforeCursor on inactive InputConnection
[WARN] : chromium: [WARNING:keycode_converter.cc(91)] empty code string
[WARN] : BindingManager: Cannot call determinedVisibility() - never saw a connection for the pid: 2990
如果我的视图是这样创建的,有问题吗:
//-- SLIDE 4
var slide_04 = Ti.UI.createView({
width:'100%',
height:'100%',
backgroundColor:'#44BBA4'
});
var label_04 = Ti.UI.createLabel({
text:"Slide 4",
color:'#222',
textAlign:'center',
font: {
fontSize:24
},
touchEnabled:false
});
slide_04.add(label_04);
scrollableDemo.addView(slide_04);
slide_04.fbProxy = FB.createActivityWorker({lifecycleContainer: slide_04});