當用戶第一次登錄到我的應用程序與facebook登錄按鈕, 我希望它重定向到FB用戶的應用程序註冊/註冊活動(key-in username/password
等),當他們再次用FB登錄, 應用程序將檢查服務器是否存在FB用戶Acc? &跳過FB的註冊活動,並重定向到主着陸頁活動,首次使用Facebook登錄登錄應用程序,將重定向到應用程序註冊頁面?
我的問題在這裏是我的代碼來檢查DB如果FB用戶已經註冊或不是?
是在:
onActivityResult(int requestCode, int resultCode, Intent data) {}?
我知道的意圖做回數據,但不知道如何訪問它,因爲我不知道額外的按鍵名稱...或者是有另一種方式爲拿到它,爲實現它?
我已經
我目前正在使用Facebook登錄按鈕,檢查了Facebook的dev的頁面,但我迷茫和不已瞭解它這個
有人可以提供我的代碼將如何看起來像一個簡單的結構?
UPDATE: 下面是我的FacebookCallback<LoginResult>()
樣子:
private FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
progressDialog.dismiss();
// App code
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
Log.e("response: ", response + "");
try {
//=================================================================//
// Create User Code
System.out.println("FB successful login");
user = new User();
//user.facebookID = object.getString("id").toString();
user.userID = object.getString("id").toString();
user.email = object.getString("email").toString();
user.name = object.getString("name").toString();
user.gender = object.getString("gender").toString();
PrefUtils.setCurrentUser(user, MainLoginActivity.this);
//STOP, if NOT Registered
//Function to check if email exist in DB
facebookCheckEmail(user.email);
if(fbresponse.equals("ok")) {
//=================================================================//
// Start MainActivity Code
Intent intent=new Intent(MainLoginActivity.this, MainActivity.class);
startActivity(intent);
Toast.makeText(MainLoginActivity.this, "Welcome " + user.name, Toast.LENGTH_LONG).show();
finish();
} else if(fbresponse.equals("no")){
//=================================================================//
// Pop up Dialog to Register & goto FB Register Activity
AlertDialog.Builder builder = new AlertDialog.Builder(getApplicationContext());
builder.setTitle("You Have Not Yet Registered");
builder.setMessage("You have not yet registered using Facebook, register now?");
builder.setPositiveButton("YES", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Goto FB Register Activity
dialog.dismiss();
}
});
builder.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// Do nothing
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
}
//=================================================================//
// Start MainActivity Code
//Intent intent=new Intent(MainLoginActivity.this, MainActivity.class);
//startActivity(intent);
//Toast.makeText(MainLoginActivity.this, "Welcome " + user.name, Toast.LENGTH_LONG).show();
//finish();
}catch (Exception e){
e.printStackTrace();
System.out.println("FB failed login = " + e.toString());
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields","id,name,email,gender,birthday");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
progressDialog.dismiss();
}
@Override
public void onError(FacebookException e) {
progressDialog.dismiss();
System.out.println("Facebook error " + e.toString());
Toast.makeText(MainLoginActivity.this, "Something goes wrong.." + e.toString(), Toast.LENGTH_LONG).show();
}
};
及以下facebookCheckEmail()
功能:
private void facebookCheckEmail(String email) {
fbCheckEmail_params = new HashMap<String, String>();
fbCheckEmail_params.put("Email", email);
final GsonRequest<FbCheckObject> gsonRequest = ApiRequest.gsonFacebookCheckEmailRequest
(
new Response.Listener<FbCheckObject>() {
@Override
public void onResponse(FbCheckObject fbCheckObject) {
try {
System.out.println("Status = " + fbCheckObject.getStatus());
if (new String(fbCheckObject.getStatus()).equals("ok") == true) {
fbresponse = "ok";
} else if(new String(fbCheckObject.getStatus()).equals("no") == true){
fbresponse = "no";
}
} catch (Exception e) {
Log.d("Web Service Error", e.getMessage());
e.printStackTrace();
}
}
}
,
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Deal with the error here
}
},
fbCheckEmail_params
);
AppController.getInstance().addToRequestQueue(gsonRequest, TAG);
}
的facebookCheckEmail
是GSONRequest,需要一個email
參數,將設置一個字符串變量fbresponse
到ok
或no
,我的問題是設置爲fbresponse
的值在facebookCheckEmail()
不更新並獲得null
當我檢查它在FacebookCallback<LoginResult>()