第一次登录使用Facebook登录应用程序,将重定向到App注册页面? [英] First time login to the app with facebook login, will redirect to app register page?
问题描述
当用户登录第一次进入我的Facebook登录按钮的应用程序,
我希望它重定向到应用程序注册/ FB对注册用户的活动(键入用户名/密码
等),下一次他们再次登录FB,
应用程序将检查服务器是否存在的FB用户加速? &安培;跳过报名参加活动FB并重定向到主着陆页活动,
When a user login first time into my app with facebook login button,
I want it to redirect them to app signup/register activity for FB users ( key-in username/password
etc), next time they login again with FB,
the app will check the server if the FB user Acc exist? & skip the sign up activity for FB and redirect to the main landing page activity,
我这里的问题是我在哪里把我的code,检查DB是否FB用户已经注册与否?
my question here is where do I place my code to check DB if the FB user is already registered or not?
是它的:
onActivityResult(int requestCode, int resultCode, Intent data) {}?
我知道你的意图返回数据,但不知道如何访问它,因为我不知道额外的按键的名字......或者有另一种方式得到它?
I know the intent do return data but have no idea how to access it, since I dont know the name of the extra keys...or is there another way to get it?
我已经检查了Facebook的开发页面,但我迷茫,不它已了解
I have checked the facebook dev page, but am confused and dont undestand it
我目前正在使用这个Facebook的登录按钮
I am currently using facebook login button for this
有人可以给我提供的code会怎么看起来像一个简单的结构?
can someone provide me a simple structure of how the code would look like?
更新:
下面是我如何 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,需要一个电子邮件
参数,将设置一个字符串变量 fbresponse
到确定
或没有
,我的问题是设置为<值code> fbresponse 在 facebookCheckEmail()
不更新并获得空
当我检查它在 FacebookCallback&LT; LoginResult&GT;()
the facebookCheckEmail
is a GSONRequest that takes a email
parameter and will set a string variable fbresponse
to the ok
or no
, my problem is the value set to fbresponse
in facebookCheckEmail()
is not updated and getting null
when I checked it in FacebookCallback<LoginResult>()
推荐答案
可以通过使用callbackmanager完成
Can be done by using callbackmanager
LoginManager.getInstance().registerCallback(mCallbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.i("NIC", "Success Login");
//Call Graph API here to retrieve user's data
//Call to you Backend to check if user is registered, then do your stuff here
}
@Override
public void onCancel() {
Toast.makeText(General_login_menu.this, "Login Cancel", Toast.LENGTH_LONG).show();
Log.i("NIC", "Cancel Login");
}
@Override
public void onError(FacebookException exception) {
Toast.makeText(General_login_menu.this, exception.getMessage(), Toast.LENGTH_LONG).show();
Log.i("NIC", "Error Login");
}
});
这篇关于第一次登录使用Facebook登录应用程序,将重定向到App注册页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!