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

关于Google People API的people.get接口无法获取其他用户姓名、照片等信息的技术问询

How to Retrieve Other Users' Name & Photos via Google People API

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 user
  • https://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.readonly and 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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.04.30 09:29:09