[英]Using ParseFacebookUtils to login android app with facebook
[英]Android ParseFacebookUtils.login callback, returning user with null objectId
我的問題基本上與這個問題相同: https : //www.parse.com/questions/parseusers-object-id-is-null-after-logging-in-using-facebook ,但沒有真正的答案線。
如果ParseFacebookUtils第一次使用login()創建用戶,一切正常。 但是,當我再次調用ParseFacebookUtils.login()時,它返回一個具有null getObjectId()的用戶
我的登錄按鈕:(已更新)
mFacebookBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
ParseFacebookUtils.logIn(LoginActivity.this, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
if (err != null) {
err.printStackTrace();
return;
}
if (user != null) {
if (user.getObjectId() == null) {
Toast.makeText(LoginActivity.this, "Weird error where object Id is null... " + user.getObjectId() + " " + user.getUsername() + " " + user.getCreatedAt() + " " + user.getUpdatedAt(), Toast.LENGTH_LONG).show();
Log.e(TAG, "Weird error where object Id is null... " + user.getObjectId() + " " + user.getUsername() + " " + user.getCreatedAt() + " " + user.getUpdatedAt());
}
else
proceedToMainActivity();
}
}
});
}
});
正如我之前所說的,如果用戶是第一次創建的,它會返回有效的對象ID,但第二次調用login()時,Log會顯示奇怪的錯誤
我正在使用Facebook SDK 3.15.0,Parse 1.5.1,並且還在設備上安裝了Facebook應用程序。
更新:此問題仍在發生,但我注意到如果我完全重新安裝該應用程序不會發生這種情況。 但是,當您注銷時,登錄時仍會發生。 這是我的注銷代碼,如果它可能會有所幫助:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
} else if (id == R.id.action_logout) {
ParseUser.logOut();
Intent intent = new Intent(this, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
更新:顯然這是一個錯誤https://developers.facebook.com/bugs/229876443869758/這對我來說仍然是一個持續存在的問題
登錄Facebook開發者網站並在設置下的應用儀表板中,檢查是否存儲了正確的密鑰哈希值和包名稱,並確保“單點登錄”已啟用。 在這里閱讀密鑰哈希。
如果您可以正確登錄用戶一次,請在注銷前嘗試刪除用戶並清除會話。
ParseUser user = ParseUser.getCurrentUser();
if(user != null)
user.deleteInBackground();
if(ParseFacebookUtils.getSession()!=null)
ParseFacebookUtils.getSession().closeAndClearTokenInformation();
ParseUser.logOut();
一件重要的事情! FacebookLogin Activity需要返回(歷史記錄)發起者活動。 如果您在清單Facebook的活動定義中有noHistory = true將無法返回。
錯誤
<activity
android:name=".LoginActivity"
android:label="Login activity"
android:noHistory="true">
</activity>
好!
<activity
android:name=".LoginActivity"
android:label="Login activity">
</activity>
現在在您的LoginActivity.java中您可以執行以下操作:
ParseFacebookUtils.logIn(this, new LogInCallback() {
@Override
public void done(ParseUser user, ParseException err) {
//here you will receive the user!!!
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.