我现在有一点这个问题而且我似乎无法找到解决方案。我已经尝试了图形API以及Profile跟踪器。两者似乎都在提出问题。 Graph API允许应用程序使用用户ID的空对象引用进行崩溃,并且在使用配置文件跟踪器时,应用程序不会继续超出该部分。
这是我的代码,其中跟踪器已注释掉,并且正在使用图形API。
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
/*if(Profile.getCurrentProfile() == null) {
profileTracker = new ProfileTracker() {
@Override
protected void onCurrentProfileChanged(Profile profile, Profile profile2) {
// profile2 is the new profile
Mint.leaveBreadcrumb("Login Activity ~ Waiting for facebook to return profile");
Log.v("facebook - profile", profile2.getFirstName());
profileTracker.stopTracking();
}
};
// no need to call startTracking() on mProfileTracker
// because it is called by its constructor, internally.
}
else {
Profile profile = Profile.getCurrentProfile();
Mint.leaveBreadcrumb("Login Activity ~ Current Profile" + profile);
Mint.leaveBreadcrumb("Login Activity ~ Current FBID" + profile.getId());
SetUserData();
LogIn();
///
continueToAdverts();
}*/
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
//String name = object.getString("name");
//String email = object.getString("email");
//String id = object.getString("id");
//Toast.makeText(MainActivity.this, name + " " + " " + email + " " + id, Toast.LENGTH_SHORT).show();
AppGlobal.LoggedUser = new UserInfo();
AppGlobal.LoggedUser.setFacebookId(object.getString("id"));
SetUserData();
LogIn();
///
continueToAdverts();
} catch (JSONException ex) {
ex.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
// App code
}
@Override
public void onError(FacebookException exception) {
// App code
}
});
我错过了什么吗?