简体   繁体   English

我们如何通过Android中的Facebook Graph API查看用户信息?

[英]How can we see users’ information through Facebook Graph API in Android?

I am making a dating app (android) by using Facebook API (You know the similar application that starts with tin…) 我正在使用Facebook API制作约会应用程序(android)(您知道以tin开头的类似应用程序…)

Anyways, I registered my application in Facebook developers and I also got approval to use functions that I need through 'Submit Items for Approval'(my Approved Items: email, public_profile, User_photo, User_like, user_work_history, user_education_history ) 无论如何,我在Facebook开发人员中注册了我的应用程序,并且还通过“提交要批准的项目”(我的已批准项目:电子邮件,public_profile,User_photo,User_like,user_work_history,user_education_history)使用了我需要的功能,

So, I can log in from my app using my Facebook ID and I can also see users' basic information too. 因此,我可以使用我的Facebook ID从我的应用登录,也可以看到用户的基本信息。

But! 但! The main problem is that I cannot see photos (except public_profile) even though I was approved for this. 主要问题是,即使我被批准也无法看到照片(public_profile除外)。

So I really need someone's help. 所以我真的需要别人的帮助。 Please help me! 请帮我!

It will be great if you can review the code I used (To use when looking at users' photos) 如果您可以查看我使用的代码,那就太好了(在查看用户照片时使用)

new Request(Session.getActiveSession(), "/{user-id}/albums", null, HttpMethod.GET, new Request.Callback() {

       @Override
       public void onCompleted(Response response) {                       }                                                  
        }).executeAsync();

You can use facebook graph api for accessing user info 您可以使用facebook graph api访问用户信息

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

To call this method, use below line, 要调用此方法,请在下面的行中使用,

request.executeAsync();

For additional info visit facebook official documentation https://developers.facebook.com/docs/android/graph 有关其他信息,请访问Facebook官方文档https://developers.facebook.com/docs/android/graph

Hey Use the following code. 嘿,使用下面的代码。 It works perfectly for me. 它非常适合我。

GraphRequest request = GraphRequest.newMeRequest(
        accessToken,
        new GraphRequest.GraphJSONObjectCallback() {
            @Override
            public void onCompleted(
                   JSONObject object,
                   GraphResponse response) {
                // Application code
            }
        });
Bundle parameters = new Bundle();
parameters.putString("fields", "photos.limit(100)");
request.setParameters(parameters);
request.executeAsync();

Try the above code and you will get a jsonobject which can be used to get the image URLs. 尝试上面的代码,您将获得一个jsonobject,可用于获取图像URL。 To know the response you get. 要知道您得到的答复。 Try Graph API explorer. 尝试使用Graph API Explorer。 The response format will be the same. 响应格式将相同。 https://developers.facebook.com/tools/explorer https://developers.facebook.com/tools/explorer

if you would like to get the photos of a user try the following code. 如果您想获取用户的照片,请尝试以下代码。 Please note that you need the user-id to they photos 请注意,您需要他们照片的用户标识

new Request(
    session,
    "/{user-id}/photos",
    null,
    HttpMethod.GET,
    new Request.Callback() {
        public void onCompleted(Response response) {
            /* handle the result */
        }
    }
).executeAsync();

Please refer to https://developers.facebook.com/docs/graph-api/reference/user/photos/ 请参考https://developers.facebook.com/docs/graph-api/reference/user/photos/

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

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