0
我正在使用SDK 4實現Facebook登錄,但只能使用一次。登錄管理器的登錄後Facebook登錄無法工作
當我安裝應用程序時,我可以完美地登錄Facebook。然而,當我退出並嘗試重新登錄時,我得到抱歉,發生了錯誤消息:
如何初始化SDK:
// Called in onCreate()
private void initFacebook() {
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.d(TAG, "On success");
getUserData(loginResult.getAccessToken());
}
@Override
public void onCancel() {
Log.d(TAG, "On cancel");
}
@Override
public void onError(FacebookException error) {
Log.d(TAG, error.toString());
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (callbackManager != null) {
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
private void getUserData(AccessToken accessToken) {
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject json,
GraphResponse response) {
Log.v(TAG, response.toString());
if (response.getError() != null) {
// handle error
Log.d(TAG, "GraphRequest error");
} else {
Log.d(TAG, "GraphRequest success");
try {
String jsonresult = String.valueOf(json);
Log.d(TAG, "JSON Result" + jsonresult);
String str_email = json.getString("email");
String str_id = json.getString("id");
String str_name = json.getString("name");
} catch (JSONException e) {
e.printStackTrace();
}
onLoginSuccess();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id, name, email");
request.setParameters(parameters);
request.executeAsync();
}
而且這裏的登錄和註銷:
@Override
public void onLoginClicked() {
LoginManager.getInstance().logInWithReadPermissions(this, Arrays.asList("email"));
}
@Override
public void onLogoutClicked() {
LoginManager.getInstance().logOut();
}
怎麼回事?
謝謝!
謝謝,但這不適合我 –