关于Google People API的people.get接口无法获取其他用户姓名、照片等信息的技术问询
Hey there, let's break down why you're hitting this roadblock and how to fix it! The core issue here is that the Google People API has built-in restrictions on accessing other users' data, and your current setup doesn't meet the requirements to pull full public/contact profile details.
1. Understand the Core Restrictions
By default, the API only lets you fetch full details for the authenticated user (using people/me). To get data for other users, two critical pieces need to align:
- Your app has the right OAuth 2.0 scopes to access public or contact-specific user data
- The target user has the profile fields you want (like name, photo) set to public (or they’re in your authenticated account’s contact list)
2. Update Your OAuth Authorization Scopes
Your current auth setup likely only includes basic scopes like profile or email—these only work for your own account. Add one of these scopes based on your needs:
https://www.googleapis.com/auth/people.readonly: Grants access to public profile data of any Google userhttps://www.googleapis.com/auth/contacts.readonly: Grants access to full profile data of users in your authenticated account’s contact list
Example: Add Scopes in Flutter's GoogleSignIn
final GoogleSignIn _googleSignIn = GoogleSignIn( scopes: [ 'email', 'profile', 'https://www.googleapis.com/auth/people.readonly', // Add this required scope ], );
3. Verify Target User's Profile Visibility
If you still don’t see fields like names after updating scopes, the target user probably has that field set to private. For example:
- A user might set their full name to "Only me" or "My contacts" in their Google Account settings
- In your sample response, only the photo is returned because that photo is marked as public, but the name is not
4. Double-Check Your Request Code
Your existing code is structured correctly, but here’s a small tweak to make field requests clearer (parentheses are optional, but this format is more widely used):
Future<Person> getPersonDetails(String peopleId) async { final GoogleAuthClient googleAuthClient = await GoogleProvider.provideGoogleAuthClient(); final PeopleServiceApi peopleServiceApi = peopleDataProvider.getPeopleApi(googleAuthClient); Person person = await peopleServiceApi.people .get(peopleId, personFields: 'names,photos,urls,emailAddresses'); return person; }
Key Takeaways
- If you’re fetching contacts, use
contacts.readonlyand ensure the user is in your authenticated account’s contact list - Public profile data is limited to what the user chooses to share publicly—you can’t access private fields no matter what scopes you use
内容的提问来源于stack exchange,提问作者hayashi

