简体   繁体   English

在Android中使用新的GRAPH API获取Facebook帐户的网址

[英]Get the URL of a facebook account using the new GRAPH API in android

Using the new graph api we manage to get the profile picture of are users(using the login with facebook button). 使用新的图形API,我们设法获取用户的个人资料图片(使用使用facebook登录)。
here's a snippet. 这是一个片段。

   GraphRequest request = GraphRequest.newMeRequest(
                accessToken,
                new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(JSONObject object, GraphResponse response) {
                        // Application code
                        try {
                            Log.i("Response", response.toString());
                            Person person = new Person();
                            person.setEmail(response.getJSONObject().getString("email"));
                            person.setName(response.getJSONObject().getString("first_name") + " " +
                                    response.getJSONObject().getString("last_name"));
                            person.setDevice_token(FirebaseInstanceId.getInstance().getToken());
                            if (response.getJSONObject().has("picture")) {
                                person.setPersonProfileImageURL(response.getJSONObject().getJSONObject("picture").getJSONObject("data").getString("url"));

                            }
                            person.setmPersonUid(uid);

                            mDatabase.setValue(person).addOnCompleteListener(new OnCompleteListener<Void>() {
                                @Override
                                public void onComplete(@NonNull Task<Void> task) {

                                    if (task.isSuccessful()) {
                                        Log.i(" mDatabase.setValue", "task.isSuccessful");
                                    }

                                }
                            });

                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });
        Bundle parameters = new Bundle();
        parameters.putString("fields", "id,email,first_name,last_name,picture.type(large)");

Is there a way to get a link to their facebook profile as well?? 有没有办法获得他们的Facebook个人资料的链接? (ie we want to show a link to the facebook profile in our app) (即,我们想在我们的应用程序中显示指向Facebook个人资料的链接)
We thought of maybe concatenating the id with facebook.com/{id} but that didn't do it. 我们考虑过将ID与facebook.com/{id}并置,但这并没有做到。
Thanks 谢谢

You need to get permission to access user_link and then try this code. 您需要获得访问user_link权限,然后尝试使用此代码。

for setting permission use this or add in you are using already. 要设置权限,请使用此选项或添加您正在使用的权限。

loginButton.setReadPermissions("user_link");

For getting profile url from graph api. 用于从图形API获取配置文件网址。

GraphRequest request = GraphRequest.newMeRequest(
  accessToken,
  new GraphRequest.GraphJSONObjectCallback() {
    @Override
    public void onCompleted(JSONObject object, GraphResponse response) {
      // do your stuff
    }
});

Bundle parameters = new Bundle();
parameters.putString("fields", "link");
request.setParameters(parameters);
request.executeAsync();

it works for me hope also works for you. 对我有用,希望对您也有用。

comment below if it works for you. 如果适合您,请在下面评论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM