我正在使用此代码,但收到无效范围错误
我想访问这个名字,姓氏和电子邮件。
任何人都可以帮我解决这个问题。
是因为facebook中的权限更改?
或其他什么?
我是否需要添加其他内容。
public class MainActivity extends AppCompatActivity {
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode,resultCode,data);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
final LoginButton loginButton= (LoginButton)findViewById(R.id.loginButton);
loginButton.setReadPermissions(Arrays.asList("email","name"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
String accessToken = loginResult.getAccessToken().getToken();
GraphRequest request= GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
progressDialog.dismiss();
getData(object);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields","id,email,first_name,last_name");
request.setParameters(parameters);
request.executeAsync();
}
});
}
private void getData(JSONObject object)
{
try{
email.setText(object.getString("email"));
first_name.setText(object.getString("first_name"));
last_name.setText(object.getString("last_name"));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
取而代之的是
first_name.setText(object.getString("first_name"));
last_name.setText(object.getString("last_name"));
}
你应该直接从facebeook获得名称
facebookUser.name = object.getString("name");
尝试检查并获取名字和姓氏,你应该拆分它。
答案 1 :(得分:0)
我已经通过电子邮件许可通过名称,删除它后不需要。谢谢你的回答
答案 2 :(得分:0)
loginButton.setReadPermissions("public_profile");
设置此权限并使用此
protected void getUserDetails(LoginResult loginResult) {
GraphRequest data_request = GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(
JSONObject json_object,
GraphResponse response) {
//here is your login is success now your requirement is start From here
//do your work
Log.e("String Response from Facebook:>",json_object.toString())
}
});
Bundle permission_param = new Bundle();
//width and height is optional parameters
permission_param.putString("fields", "id,name,email,picture.width(120).height(120)");
data_request.setParameters(permission_param);
data_request.executeAsync();