質問

Can't figure out why my Android app with Facebook Login (SDK 3.6) is only working with my phone only. And by that I mean it won't get past the Login Activity. When another person tries to test the app (running it in Eclipse), they click the Login with Facebook button and it asks their permission to access their Facebook info. When they click ok, it brings it back to the Login Activity as if nothing happened.

I am still in the development phase so I am trying to test the app through .

I am thinking that when I gave all the project files to the other person to test, it still has my Session information logged in? Two different Facebook accounts btw.

I generate the keyhash while running the program. The block of code is in there.

LoginActivity code

public class LoginActivity extends Activity {

private static final int HTTP_RESPONSE_SUCCESS = 200;

private Preferences prefs;
public List<GraphUser> fbFriends;

private UiLifecycleHelper uiHelper;
private Session.StatusCallback callback = new Session.StatusCallback() {
    @Override
    public void call(Session session, SessionState state, Exception exception) {
        onSessionStateChange(session, state, exception);
    }
};

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    getActionBar().setTitle("");

    uiHelper = new UiLifecycleHelper(this, callback);
    uiHelper.onCreate(savedInstanceState);

    prefs = new Preferences(this);

    getKeyHash();
}

private void goToMainActivity() {
    Intent intent = new Intent(this, MainActivity.class);
    startActivity(intent);
}

private void getKeyHash() {
    try {
        PackageInfo info = getPackageManager().getPackageInfo("com.walintukai.derpteam", 
                PackageManager.GET_SIGNATURES);
        for (Signature signature : info.signatures) {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(signature.toByteArray());
            Log.i("KeyHash:", Base64.encodeToString(md.digest(), Base64.DEFAULT));
        }
    } 
    catch (NameNotFoundException e) { } 
    catch (NoSuchAlgorithmException e) { }
}

private void onSessionStateChange(Session session, SessionState state, Exception exception) {
    if (session.isOpened()) {
        Request.newMeRequest(session, new Request.GraphUserCallback() {
            @Override
            public void onCompleted(GraphUser user, Response response) {
                if (user != null) {
                    prefs.setFbUserId(user.getId());
                    prefs.setFbUserName(user.getName());
                    Log.i("FB LOGIN", user.getName());
                }
            }
        }).executeAsync();

        requestFacebookFriends(Session.getActiveSession());
        goToMainActivity();
    }
    else if (session.isClosed()) {
        Log.i("FB LOGOUT", "");
        prefs.setFbUserId("");
        prefs.setFbUserName("");
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    uiHelper.onActivityResult(requestCode, resultCode, data);
}

private void requestFacebookFriends(Session session) {
    Request friendsRequest = createRequest(session);
    friendsRequest.setCallback(new Request.Callback() {
        @Override
        public void onCompleted(Response response) {
            fbFriends = getResults(response);

            JSONWriter writer = new JSONWriter(LoginActivity.this);
            writer.updateFriendsList(fbFriends);
            writer.logJson("friends.json");

            new PostToServerTask().execute();
        }
    });
    friendsRequest.executeAsync();
}

private Request createRequest(Session session) {
    Request request = Request.newGraphPathRequest(session, "me/friends", null);

    Set<String> fields = new HashSet<String>();
    String[] requiredFields = new String[] {"id", "name"};
    fields.addAll(Arrays.asList(requiredFields));

    Bundle parameters = request.getParameters();
    parameters.putString("fields", TextUtils.join(",", fields));
    request.setParameters(parameters);

    return request;
}

private List<GraphUser> getResults(Response response) {
    GraphMultiResult multiResult = response.getGraphObjectAs(GraphMultiResult.class);
    GraphObjectList<GraphObject> data = multiResult.getData();
    return data.castToListOf(GraphUser.class);
}

private class PostToServerTask extends AsyncTask<Void, Void, Void> {
    private int responseCode;

    protected Void doInBackground(Void... params) {
        HttpPostRequest post = new HttpPostRequest(LoginActivity.this);
        post.createPost();
        post.addJSON("friends.json");
        responseCode = post.sendPost();
        return null;
    }

    protected void onPostExecute(Void result) {
        super.onPostExecute(result);
        if (responseCode == HTTP_RESPONSE_SUCCESS ) { Log.i("POST TO SERVER", "SUCCESS"); }
        else { Log.e("POST TO SERVER", "ERROR"); }
        return;
    }
}

@Override
protected void onDestroy() {
    super.onDestroy();
    uiHelper.onDestroy();
}

@Override
protected void onPause() {
    super.onPause();
    uiHelper.onPause();
}

@Override
protected void onResume() {
    super.onResume();
    uiHelper.onResume();
}

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    uiHelper.onSaveInstanceState(outState);
}

}

役に立ちましたか?

解決 2

All I had to do was take the app out of Sandbox Mode. Problem solved!

他のヒント

You missed one thing. Go to https://developers.facebook.com, select your app -> Settings -> Android block and add key hashes for other computers (check https://developers.facebook.com/docs/android/getting-started/ for details)
enter image description here

To get hash run keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 for Mac OS
and keytool -exportcert -alias androiddebugkey -keystore %HOMEPATH%\.android\debug.keystore | openssl sha1 -binary | openssl base64 for windows

This is problem, your facebook app not public. You have to click Status&Review menu on https://developers.facebook.com/apps/ site. Then quesiton "Do you want to make this app and all its live features available to the general public?" answer "YES" and save. that's all.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top