Android 无效范围:单击登录按钮时显示id错误?
这是我代码的摘录。我设置读取权限或应用graph api请求的方式是否有任何问题Android 无效范围:单击登录按钮时显示id错误?,android,facebook-graph-api,Android,Facebook Graph Api,这是我代码的摘录。我设置读取权限或应用graph api请求的方式是否有任何问题 LoginButton loginButton = (LoginButton)findViewById(R.id.login_button); ArrayList<String> perList=new ArrayList<>(); perList.add("id"); perList.add("email"); //l
LoginButton loginButton = (LoginButton)findViewById(R.id.login_button);
ArrayList<String> perList=new ArrayList<>();
perList.add("id");
perList.add("email");
//loginButton.setReadPermissions("id","email","user_birthday","user_location");
loginButton.setReadPermissions(perList);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Toast.makeText(getApplicationContext(),"facebook login success",Toast.LENGTH_SHORT).show();
AccessToken at=loginResult.getAccessToken();
String userId=loginResult.getAccessToken().getUserId();
Ion.with(getApplicationContext()).load("graph.facebook.com/"+userId+"/picture?type=large").setTimeout(60*1000)
.asJsonObject().setCallback(new FutureCallback<JsonObject>() {
@Override
public void onCompleted(Exception e, JsonObject result) {
Toast.makeText(getApplicationContext(),"inOnComoplete",Toast.LENGTH_SHORT).show();
}
});
}
LoginButton LoginButton=(LoginButton)findViewById(R.id.login_按钮);
ArrayList perList=新建ArrayList();
添加(“id”);
添加(“电子邮件”);
//setReadPermissions(“id”、“电子邮件”、“用户生日”、“用户位置”);
设置读取权限(perList);
registerCallback(callbackManager,newfacebookcallback()){
@凌驾
成功时公共无效(LoginResult LoginResult){
Toast.makeText(getApplicationContext(),“facebook登录成功”,Toast.LENGTH_SHORT.show();
AccessToken at=loginResult.getAccessToken();
字符串userId=loginResult.getAccessToken().getUserId();
Ion.with(getApplicationContext()).load(“graph.facebook.com/”+userId+“/picture?type=large”).setTimeout(60*1000)
.asJsonObject().setCallback(新的FutureCallback()){
@凌驾
未完成公共无效(异常e,JsonObject结果){
Toast.makeText(getApplicationContext(),“inoncomplete”,Toast.LENGTH\u SHORT.show();
}
});
}
试试这个
loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("public_profile, email"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
@Override
public void onSuccess(LoginResult loginResult) {
Log.e("TESTCHK", "1");
GraphRequest request = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
@Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.e("DAta", response.toString());
Log.e("TESTCHK", "2");
try {
Intent intent = new Intent(MainActivity.this, ResultActivity.class);
intent.putExtra("img", object.getJSONObject("picture").getJSONObject("data").getString("url"));
intent.putExtra("name", "Name is : " + object.getString("name") + "\nEmail is : " + object.getString("email"));
startActivity(intent);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle bundle = new Bundle();
//bundle.putString("fields", "id,name,email,gender,birthday");
bundle.putString("fields", "name,email,picture.type(large)");
request.setParameters(bundle);
request.executeAsync();
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
Toast.makeText(MainActivity.this, "Error while login with facebook", Toast.LENGTH_SHORT).show();
}
});
loginButton=(loginButton)findviewbyd(R.id.login_按钮);
setReadPermissions(Arrays.asList(“public_profile,email”);
registerCallback(callbackManager,newfacebookcallback()){
@凌驾
成功时公共无效(LoginResult LoginResult){
Log.e(“TESTCHK”,“1”);
GraphRequest request=GraphRequest.NewMereRequest(loginResult.getAccessToken(),new GraphRequest.GraphJSONObjectCallback()){
@凌驾
未完成公共无效(JSONObject对象,GraphResponse响应){
Log.e(“DAta”,response.toString());
Log.e(“TESTCHK”,“2”);
试一试{
意向意向=新意向(MainActivity.this、ResultActivity.class);
intent.putExtra(“img”,object.getJSONObject(“图片”).getJSONObject(“数据”).getString(“url”);
intent.putExtra(“名称”,“名称是:”+object.getString(“名称”)+“\n邮件是:”+object.getString(“电子邮件”);
星触觉(意向);
}捕获(JSONException e){
e、 printStackTrace();
}
}
});
Bundle=新Bundle();
//bundle.putString(“字段”、“id、姓名、电子邮件、性别、生日”);
bundle.putString(“字段”、“名称、电子邮件、图片.类型(大)”);
设置参数(捆绑);
request.executeAsync();
}
@凌驾
公开作废{
}
@凌驾
public void onError(facebook异常错误){
Toast.makeText(MainActivity.this,“使用facebook登录时出错”,Toast.LENGTH_SHORT.show();
}
});
如果有任何查询,请询问我我已经应用了facebook登录按钮,根本没有名为
id
的权限,因此您尝试要求用户将其授予您的应用程序是毫无意义的……耶,我后来意识到了这一点。