在我集成 facebook 登录的应用程序中,facebook 登录工作正常,但每次都要求登录。
我通过 facebook 登录工作正常,在我的应用程序中使用应用程序请求,而应用程序请求也要求 facebook 登录。
我想避免告诉我一些想法来做到这一点,
我的登录代码:
Session.openActiveSession(Notication_Webview.this, true, new Session.StatusCallback() {
@Override
public void call(final Session session, SessionState state, Exception exception) {
// TODO Auto-generated method stub
if(session.isOpened()){
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
@Override
public void onCompleted(GraphUser user, Response response) {
// TODO Auto-generated method stub
if(user!=null){
try{
userName=user.getFirstName();//obj.getString("first_name");
facebookId=user.getId();//obj.getString("id");
}catch (Exception e) {
Log.e(tag, "getUserIdMethod--->"+e);
}
}
}
});
}
}
});
在此应用程序请求代码中,
Session session = Session.getActiveSession();
Facebook mFb = new Facebook("app id");
Bundle params = new Bundle();
params.putString("to", userIDString);
params.putString("message", Message);
mFb.dialog(this.getParent(), "apprequests",
params, new DialogListener() {
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
}
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
}
public void onError(DialogError e) {
// TODO Auto-generated method stub
}
public void onCancel() {
// TODO Auto-generated method stub
}
});
mFb.dialod 方法:
@Deprecated
public void dialog(Context context, String action, Bundle parameters, final DialogListener listener) {
parameters.putString("display", "touch");
parameters.putString("redirect_uri", REDIRECT_URI);
if (action.equals(LOGIN)) {
parameters.putString("type", "user_agent");
parameters.putString("client_id", mAppId);
} else {
parameters.putString("app_id", mAppId);
// We do not want to add an access token when displaying the auth dialog.
if (isSessionValid()) {
parameters.putString(TOKEN, getAccessToken());
}
}
if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET) != PackageManager.PERMISSION_GRANTED) {
Util.showAlert(context, "Error", "Application requires permission to access the Internet");
} else {
new FbDialog(context, action, parameters, listener).show();
}
}
告诉我如何避免第二次登录。