You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android端Facebook Graph API仅返回name和id,求助获取完整public_profile信息

Troubleshooting Facebook Graph API Only Returning name and id in Android (Gradle Project)

Hey there! I’ve run into this exact issue before, so let’s break down what’s going on and how to fix it:

1. You’re Not Explicitly Requesting the Required Fields

Starting with Graph API v2.4+, Facebook doesn’t return all public_profile fields by default—even if you’ve requested the right scopes. You need to explicitly specify which fields you want in your request.

For example, instead of just calling /me, append the fields parameter to define exactly what data you want:

GraphRequest request = GraphRequest.newMeRequest(
    AccessToken.getCurrentAccessToken(),
    new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(JSONObject object, GraphResponse response) {
            // Handle your response data here
        }
    });
Bundle parameters = new Bundle();
// List all fields you need from public_profile, email, and user_birthday
parameters.putString("fields", "id,name,email,birthday,gender,first_name,last_name,profile_picture");
request.setParameters(parameters);
request.executeAsync();

This tells Facebook to send back the specific fields you’ve listed, rather than just the default id and name.

2. Verify the User Actually Granted the Permissions

Setting scopes in your login flow doesn’t guarantee the user accepted all of them—users can choose to deny certain permissions during authorization.

To check which permissions are currently granted, make a quick request to /me/permissions:

GraphRequest permissionCheckRequest = GraphRequest.newGraphPathRequest(
    AccessToken.getCurrentAccessToken(),
    "/me/permissions",
    new GraphRequest.GraphJSONObjectCallback() {
        @Override
        public void onCompleted(JSONObject object, GraphResponse response) {
            try {
                JSONArray permissions = object.getJSONArray("data");
                for (int i = 0; i < permissions.length(); i++) {
                    JSONObject perm = permissions.getJSONObject(i);
                    String permName = perm.getString("permission");
                    String status = perm.getString("status");
                    Log.d("FB Permissions", permName + ": " + status);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    });
permissionCheckRequest.executeAsync();

If email or user_birthday show a status of declined, you’ll need to prompt the user to re-authorize those permissions.

3. Check if Permissions Need Facebook Review

For non-test users, certain permissions like user_birthday require Facebook’s app review before they’re accessible in production. If you’re testing with a regular user (not added as a test user in your Facebook Developer Dashboard), you might only get default fields until the permission is approved.

Head to your Facebook App Dashboard, navigate to App Review > Permissions and Features, and check if user_birthday and email are marked as "Approved" or need to be submitted for review.

4. Ensure You’re Using a Compatible Facebook SDK Version

Outdated versions of the Facebook Android SDK can cause unexpected behavior with permission handling or field requests. Make sure your module-level build.gradle has the latest SDK dependency:

dependencies {
    // Replace with the latest stable version (check Facebook's docs for updates)
    implementation 'com.facebook.android:facebook-android-sdk:17.0.0'
}

After updating, sync your Gradle project and test again.

Quick Debug Checklist

  1. Add the explicit fields parameter to your request (this is the most common fix).
  2. Confirm the user granted all requested permissions via the /me/permissions endpoint.
  3. Verify if your app needs permission review for non-test users.
  4. Update your Facebook SDK to the latest compatible version.

Let me know if any of these steps get you the full data you need!

内容的提问来源于stack exchange,提问作者Sathya Baman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:31:01