咨询:是否有适用于iOS平台的Google People API示例及实现帮助?
Hey there! Great question—Google People API does have support for iOS, even if the getting-started page you referenced doesn’t highlight iOS-specific examples upfront. Let me walk you through the key steps and resources to get started:
iOS Support for Google People API
Here’s what you need to know to integrate the People API into your iOS app:
- Authenticate with Google Sign-In for iOS: This is a mandatory first step. You’ll need to set up the Google Sign-In SDK to handle user authentication, which grants your app the OAuth 2.0 credentials required to make calls to the People API. The SDK manages the entire auth flow, so you don’t have to build it from scratch.
- Use the Official Client Library: Google provides a client library for iOS (supporting both Swift and Objective-C) that wraps the People API endpoints. You can add it to your project via CocoaPods using the command:
If you prefer Swift Package Manager, you can find the library listed in the official package repository.pod 'GoogleAPIClientForREST/People' - Quick Swift Implementation Example: Once you have a signed-in user, here’s a simple snippet to fetch their basic profile information:
import GoogleAPIClientForREST import GoogleSignIn func fetchUserProfile() { let peopleService = GTLRPeopleServiceService() // Attach the authenticated user's authorizer to the service peopleService.authorizer = GIDSignIn.sharedInstance.currentUser?.authentication.fetcherAuthorizer() // Create a query to fetch the user's name and email let query = GTLRPeopleServiceQuery_PeopleGet.query(withResourceName: "people/me", personFields: "names,emailAddresses") // Execute the query peopleService.executeQuery(query) { (ticket, result, error) in if let error = error { print("Error fetching profile: \(error.localizedDescription)") return } guard let person = result as? GTLRPeopleService_Person else { return } // Access the profile data let firstName = person.names?.first?.givenName let email = person.emailAddresses?.first?.value print("User: \(firstName ?? "Unknown"), Email: \(email ?? "No email")") } } - Additional iOS-Specific Resources:
- The Google Sign-In for iOS documentation includes step-by-step guides for integrating it with the People API.
- The official Google APIs Client Library repo has sample iOS projects that demonstrate real-world usage of the People API.
- When enabling the People API in your Google Cloud Console project, there are iOS-specific setup instructions to configure your app’s bundle ID and credentials.
内容的提问来源于stack exchange,提问作者Niraj
相关产品推荐
相关产品推荐

