Facebook的登录工作不正常(解析) [英] Facebook Login not working properly (Parse)
问题描述
在我的应用程序,我有一个处理Facebook的登录和注册的活动。当我点击我的登录与Facebook按钮,我执行此code,因为写的解析文档:
ParseFacebookUtils.logIn(这一点,新LogInCallback(){
@覆盖
公共无效完成(ParseUser用户,ParseException的错误){
如果(用户== NULL){
Log.d(应用标签,嗯哦用户取消了Facebook登录);
}否则如果(user.isNew()){
Log.d(应用标签,用户注册并通过Facebook登录!);
}其他{
Log.d(应用标签,用户登录通过Facebook!);
}
}
});
这应该是处理新用户和现有用户。
我也有这个方法在我的活动:
@覆盖
保护无效的onActivityResult(INT申请code,INT结果code,意图数据){
super.onActivityResult(要求code,结果code,数据);
ParseFacebookUtils.finishAuthentication(要求code,结果code,数据);
}
在我的应用
类,我成立了解析和ParseFacebookUtils正确的:
Parse.initialize(这一点,的getString(R.string.parse_app_id)的getString(R.string.parse_client_key));
ParseFacebookUtils.initialize(的getString(R.string.facebook_app_id));
我也有我的设备上安装Facebook应用程序。
我的问题是,当我称之为 ParseFacebookUtils.logIn()
,它总是返回ParseUser,这不是新的或空,但那是用途不同空。它没有 OBJECTID
, createdAt
, updatedAt
等。在 ParseException的
也总是空。
我也不知道为什么 ParseUser
在完成
回调有一个假值 user.isNew()
,因为没有在我的 _user
表中的任何用户。通常情况下,Facebook的登录应该创建一个新的 ParseUser
如果不存在。
我试着卸载并重新安装我的应用程序,但没有奏效。即使我清楚每个表,数据浏览器,清空缓存,并得到一个完全重新安装我的应用程序,它永远不会显示用户都是新的。
我发现了一个的解析帮助论坛类似的帖子一>,但没有答案。
在我的 AndroidManifest
,我有这样的:
<活动
机器人:名字=com.facebook.LoginActivity
机器人:标签=@字符串/ APP_NAME
机器人:主题=@安卓风格/ Theme.Translucent.NoTitleBar/> &所述;元数据
机器人:名字=com.facebook.sdk.ApplicationId
机器人:值=@字符串/ facebook_app_id/><活动
机器人:名字=。activities.SignUpOrLogInActivity
机器人:标签=@字符串/ APP_NAME
机器人:主题=@安卓风格/ Theme.Black.NoTitleBar/>
的 SignUpOrLogInActivity
是我有我登录与Facebook按钮。
在我的日志,我有时会看到这样的警告:
警告:无会话请求需要令牌,但缺少任一应用程序ID或客户端令牌。
然后我试图登录Facebook的应用程序ID和访问令牌是这样的:
ParseFacebookUtils.getSession()。getApplicationId()
和
ParseFacebookUtils.getSession()。getAccessToken()
Facebook应用程序ID是正确的,会话令牌印刷一些字符串看起来正确的。
我有解析版本: 1.5.1 和Facebook SDK版本的 3.14.1
编辑:
我看着在我的云code日志,发现这个错误:
I2014-08-17T18:12:35.381Z] v314:before_save触发_user
输入: {\"original\":null,\"update\":{\"username\":\"n7Tr5fvBGumtCv2MxwY8V3PHF\",\"authData\":{\"facebook\":{\"id\":\"[my_fb_id]\",\"access_token\":\"CAAEK5cQebpEBAHz2vgqtJ3ADuoAIWJb6pos1ykobZCi4PjwsZAVLuN14EiOTJJLdhR97iiwSefSU5nvlVSq5ZBCiopyTycpsQDw5jM7rnBZBUrWvrbPcTIAmp8JomPAXmTrUok93BDhdireVrtxED86ziaxm29nUCuhb2PHMQZAWGNTDyKkxdeUthsFzC7F4WmmKCQUJpZAwYlebHWOfI9y02B0O8DNSZARTLjfpmZCvXQZDZD\",\"expiration_date\":\"2014-10-16T16:11:57.000Z\"}}}}
结果:无效的电子邮件。
的问题是,我曾经为分析用户类像这样的保存功能之前:
Parse.Cloud.beforeSave(Parse.User,功能(请求,响应){
VAR用户= request.object;
如果(!/ ^([A-Z0-9 _ \\ .-] +)@([\\ DA-Z \\ .-] +)\\。(即[az \\。] {2,6})$ /测试( user.get(电子邮件))){
response.error(无效的电子邮件。);
}否则如果(!user.get(电子邮件)){
response.error(每个用户必须拥有一个电子邮件地址。);
}其他{
response.success();
}
});
我摆脱这个来解决该问题。
In my app, I have an activity that handles the Facebook sign in and sign up. When I click my "Sign in with Facebook" button, I execute this code, as written the Parse docs:
ParseFacebookUtils.logIn(this, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
if (user == null) {
Log.d(APPTAG, "Uh oh. The user cancelled the Facebook login.");
} else if (user.isNew()) {
Log.d(APPTAG, "User signed up and logged in through Facebook!");
} else {
Log.d(APPTAG, "User logged in through Facebook!");
}
}
});
This is supposed to handle new and existing users.
I also have this method in my activity:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
ParseFacebookUtils.finishAuthentication(requestCode, resultCode, data);
}
In my Application
class, I set up Parse and ParseFacebookUtils properly:
Parse.initialize(this, getString(R.string.parse_app_id), getString(R.string.parse_client_key));
ParseFacebookUtils.initialize(getString(R.string.facebook_app_id));
I also have the Facebook App installed on my device.
The problem I have is that when I call ParseFacebookUtils.logIn()
, it always returns a ParseUser that's not new or null, but that is effectivly empty. It has no objectId
, createdAt
, updatedAt
, etc. The ParseException
also is always null.
I'm also not sure why the ParseUser
in the done
callback has a false value for user.isNew()
because there aren't any users in my _User
table. Usually, the Facebook sign in should create a new ParseUser
if one doesn't already exist.
I've tried uninstalling and re-installing my app but that didn't work. Even If I clear every table, in the Data Browser, clear my cache, and get a completely fresh install of my app, It never shows that the user is new.
I found a similar post on the Parse help forum, but there were no answers.
In my AndroidManifest
, I have this:
<activity
android:name="com.facebook.LoginActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity
android:name=".activities.SignUpOrLogInActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar" />
The SignUpOrLogInActivity
is where I have my "Sign in with Facebook" button.
In my log, I sometimes see this warning:
Warning: Sessionless Request needs token but missing either application ID or client token.
I then tried to log the Facebook application Id and access token like this:
ParseFacebookUtils.getSession().getApplicationId()
and
ParseFacebookUtils.getSession().getAccessToken()
The Facebook app id is correct and the session token printed some string that looked correct.
I have Parse Version: 1.5.1 and Facebook SDK version 3.14.1.
Edit:
I looked in my Cloud Code log and found this error:
I2014-08-17T18:12:35.381Z] v314: before_save triggered for _User
Input: {"original":null,"update":{"username":"n7Tr5fvBGumtCv2MxwY8V3PHF","authData":{"facebook":{"id":"[my_fb_id]","access_token":"CAAEK5cQebpEBAHz2vgqtJ3ADuoAIWJb6pos1ykobZCi4PjwsZAVLuN14EiOTJJLdhR97iiwSefSU5nvlVSq5ZBCiopyTycpsQDw5jM7rnBZBUrWvrbPcTIAmp8JomPAXmTrUok93BDhdireVrtxED86ziaxm29nUCuhb2PHMQZAWGNTDyKkxdeUthsFzC7F4WmmKCQUJpZAwYlebHWOfI9y02B0O8DNSZARTLjfpmZCvXQZDZD","expiration_date":"2014-10-16T16:11:57.000Z"}}}}
Result: Invalid email.
The problem was that I had a before save function for the Parse User class like this:
Parse.Cloud.beforeSave(Parse.User, function(request, response) {
var user = request.object;
if (!/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/.test(user.get("email"))) {
response.error("Invalid email.");
} else if (!user.get("email")) {
response.error("Every user must have an email address.");
} else {
response.success();
}
});
I got rid of this to fix the issue.
这篇关于Facebook的登录工作不正常(解析)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!