• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

FB login is not working when native fb app is installed?

 
prashant verma
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hii guys, I have tried many times and but I am still unable to find the issue. The case is that I am having a fb login button which works good untill fb app is not installed and if it is installed than fb login is only fetching data for those ussers that are listed as tester or developer in my app. My app at fb is live and working. I am pasting my fb code below. Please guide me in this issue. thanks in advance.

public void signInWithFacebook() {

Constant.printKeyHash(MainActivity.this);
mSessionTracker = new SessionTracker(mContext, new Session.StatusCallback() {
@Override
public void call(Session session, SessionState state, Exception exception) {
}
}, null, false);

String applicationId = Utility.getMetadataApplicationId(mContext);
Constant.mCurrentSession = mSessionTracker.getSession();

if (Constant.mCurrentSession == null || Constant.mCurrentSession.getState().isClosed()) {
mSessionTracker.setSession(null);
Log.d("session status","session null");
Session session = new Session.Builder(mContext).setApplicationId(applicationId).build();
Session.setActiveSession(session);
Constant.mCurrentSession = session;
} else {
mSessionTracker.setSession(null);
Session session = new Session.Builder(mContext).setApplicationId(applicationId).build();
Session.setActiveSession(session);
Constant.mCurrentSession = session;
}

if (!Constant.mCurrentSession.isOpened()) {
Session.OpenRequest openRequest = null;
Log.d("session status","session open");
openRequest = new Session.OpenRequest((Activity) mContext);

if (openRequest != null) {
Log.d("setting permissions","setting permissions");
openRequest.setDefaultAudience(SessionDefaultAudience.FRIENDS);
openRequest.setPermissions(Arrays.asList("user_birthday", "email", "user_location", "user_friends"));
openRequest.setLoginBehavior(SessionLoginBehavior.SSO_WITH_FALLBACK);

Constant.mCurrentSession.openForRead(openRequest);

try {
// progressfb.show();
// progressfb.setCancelable(false);
} catch (Exception e) {

}
Log.d("accessing permissions","accessing permissions");
accessFacebookUserInfo();
}
} else {

// progressfb.show();
accessFacebookUserInfo();

}
}


public void accessFacebookUserInfo() {
if (Session.getActiveSession() != null || Session.getActiveSession().isOpened()) {
Bundle bundle = new Bundle();
bundle.putString("fields","picture,email,first_name, last_name, name");
// bundle.putString("fields", "email");
// bundle.putString("fields", "first_name");
Log.d("accessFacebookUserInfo","accessFacebookUserInfo");
final Request request = new Request(Session.getActiveSession(), "me", bundle, HttpMethod.GET, new Request.Callback() {
@SuppressWarnings("unused")
@Override
public void onCompleted(Response response) {

Log.d("onCompleted","onCompleted called");

GraphObject graphObject = response.getGraphObject();

Log.d("GraphObject", String.valueOf(graphObject));

if (graphObject != null) {
try {

Log.d("creating json ","new json created");
JSONObject jsonObject = new JSONObject();
jsonObject = graphObject.getInnerJSONObject();

Log.i("", "faacebook response===" + jsonObject.toString());

String facebook_id = jsonObject.getString("id");
JSONObject picture_obj = jsonObject.getJSONObject("picture");
JSONObject picture_data = picture_obj.getJSONObject("data");

// fb_pic_url = picture_data.getString("url");

String first_name = jsonObject.getString("name");
String last_name = jsonObject.getString("last_name");
String socialName = jsonObject.getString("name");
eemail = jsonObject.getString("email");

String fb_pic_url = "https://graph.facebook.com/"
+ facebook_id
+ "/picture?type=large";

// progress.dismiss();
Toast.makeText(mContext, "fb_id" + facebook_id + "firstname" + first_name + "email" + eemail,
Toast.LENGTH_LONG).show();


Toast.makeText(mContext, "Please wait..", Toast.LENGTH_LONG).show();
new fbSigninActivity().execute(eemail, first_name);
callFacebookLogout(MainActivity.this);

} catch (Exception e) {
e.printStackTrace();

Toast.makeText(mContext, "something went wrong", Toast.LENGTH_LONG).show();
}
}
}
});
Request.executeBatchAsync(request);

}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// super.onActivityResult(requestCode, resultCode, data);
Log.d("resultCode", String.valueOf(resultCode));
if (resultCode == RESULT_OK ) {
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
if (Constant.mCurrentSession.isOpened()) {

accessFacebookUserInfo();

} else {
//Utils.showCenterToast(contxt, getResources().getString(R.string.msg_went_wrong));

}
// else {
Constant.mCurrentSession = null;
mSessionTracker.setSession(null);
// progressfb.dismiss();

}

}

public static void callFacebookLogout(Context context) {
Session session = Session.getActiveSession();
if (session != null) {

if (!session.isClosed()) {
session.closeAndClearTokenInformation();
//clear your preferences if saved
}
} else {

session = new Session(context);
Session.setActiveSession(session);

session.closeAndClearTokenInformation();
//clear your preferences if saved

}

}
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic