是否有使用 Facebook SDK 代码示例的后端实现?我已经这样做了,但我在后端看不到用户的数据。
这是我的代码。
private FacebookCallback<LoginResult> mCallBack = new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.e("response: ", response + "");
Backendless.UserService.loginWithFacebookSdk(LoginActivity.this,
callbackManager,
new AsyncCallback<BackendlessUser>() {
@Override
public void handleResponse(BackendlessUser response) {
user = new User();
user.setFacebookID((String) response.getProperty("id"));
user.setName((String) response.getProperty("name"));
user.setEmail((String) response.getProperty("email"));
user.setGender((String) response.getProperty("gender"));
user.setLocale((String) response.getProperty("locale"));
}
@Override
public void handleFault(BackendlessFault fault) {
Toast.makeText(getApplicationContext(), fault.getMessage(), Toast.LENGTH_SHORT).show();
}
});
}
}
);
Bundle parameters = new Bundle();
parameters.putString("fields", "id, name, email, gender, locale, birthday, picture.width(80).height(80)");
request.setParameters(parameters);
request.executeAsync();
}
@Override
public void onCancel() {
Log.i(TAG, "LoginButton FacebookCallback onCancel");
}
@Override
public void onError(FacebookException error) {
Log.i(TAG, "LoginButton FacebookCallback onError:: "+error.getMessage());
Log.i(TAG, "Exception:: "+error.getStackTrace());
}
}
映射
Map<String, String> facebookFieldMappings = new HashMap<String, String>() {{
put("id", "fb_id");
put("first_name", "fb_first_name");
put("last_name", "fb_last_name");
put("email", "email");
put("gender", "fb_gender");
}};