求助:使用Facebook OpenGraph API获取用户任职信息失败
Hey there, let's work through why your work field request is only returning the user ID instead of the job or company info you're targeting. Here are the key fixes to try out:
1. You're Missing the Required Permission
The work field can't be accessed with a basic access token—it requires the user_work_history permission. Here's how to add it in the OpenGraph Explorer:
- Click the "Get Token" dropdown in the top-right corner.
- Select "Get User Access Token".
- In the permission list, find and check the
user_work_historybox. - Click "Get Access Token" and follow the prompts to authorize this permission for your test account.
Once you have the updated token, re-run your request—you should see work data if it exists on the user's profile.
2. Request Specific Nested Fields
The work field returns an array of objects with nested details (like employer name, position title, etc.). If you only request work, you might get truncated data, or just the user ID if permissions are still missing. Try specifying the exact subfields you need with this request:
{user-id}?fields=work{employer{name},position{name},start_date,end_date}
This will directly pull the company name (employer.name) and job title (position.name) along with optional start/end dates.
3. Check the User's Privacy Settings
Even with the right permissions, if the user's work history is set to a strict privacy level (e.g., "Only Me"), your app won't be able to access it. Ask your test user to:
- Go to their Facebook profile, edit their work experience entry.
- Adjust the privacy setting for that entry to allow access from your app (or set it to "Friends" / "Public" for testing purposes).
4. Use the Latest Stable API Version
Older API versions might have deprecated or changed how the work field is accessed. In the Explorer's top bar, select the newest stable API version (e.g., v18.0) before running your request to avoid compatibility issues.
Bonus Note for Public Apps
If you're building an app for non-test users, the user_work_history permission requires Facebook's app review. You'll need to submit your app for review and explain why you need access to this data before it can be used with regular users.
内容的提问来源于stack exchange,提问作者ducci

