我浏览了 Google People API 的文档。
https://developers.google.com/people/v1/getting-started
我找不到任何帮助/示例来为 iOS 平台实现相同的功能。 iOS 平台有可用的帮助吗?
最佳答案
是的,有一个适用于 iOS 的 People API 客户端库。要包含您指定的内容
pod 'GoogleAPIClientForREST/PeopleService', '~> 1.3.4'
pod 'GoogleSignIn', '~> 4.1.2'
在 Cocoapods pod 文件中。
不,除了 https://github.com/google/google-api-objectivec-client-for-rest 上的源库本身之外,我还没有找到适用于 iOS 的 Google People API 客户端库的任何文档。
使用 Google Calendar API iOS Swift 示例代码作为指导、设置
private let scopes = [kGTLRAuthScopePeopleServiceContactsReadonly]
private let service = GTLRPeopleServiceService()
以下代码读取登录用户的联系人列表。
// MARK: - Get Google Contacts
@objc func fetchContacts() {
let query = GTLRPeopleServiceQuery_PeopleConnectionsList.query(withResourceName: "people/me")
query.personFields = "names,emailAddresses,photos"
service2.executeQuery(
query,
delegate: self,
didFinish: #selector(getCreatorFromTicket(ticket:finishedWithObject:error:)))
}
@objc func getCreatorFromTicket(
ticket: GTLRServiceTicket,
finishedWithObject response: GTLRPeopleService_ListConnectionsResponse,
error: NSError?) {
if let error = error {
showAlert(title: "Error", message: error.localizedDescription)
return
}
if let connections = response.connections, !connections.isEmpty {
for connection in connections {
if let names = connection.names, !names.isEmpty {
for name in names {
if let _ = name.metadata?.primary {
print(name.displayName ?? "")
}
}
}
if let emailAddresses = connection.emailAddresses, !emailAddresses.isEmpty {
for email in emailAddresses {
if let _ = email.metadata?.primary {
print(email.value ?? "")
}
}
}
if let photos = connection.photos, !photos.isEmpty {
for photo in photos {
if let _ = photo.metadata?.primary {
print(photo.url ?? "")
}
}
}
}
}
}
ps 要使 Google Calendar API iOS Swift 示例构建没有错误,您可能需要添加一个桥接头文件("file">“新建”>"file",选择头文件)并添加以下内容:
#import <GTMSessionFetcher/GTMSessionFetcher.h>
#import <GTMSessionFetcher/GTMSessionFetcherService.h>
然后在 Swift Compiler - General 标题下的目标 Build Settings 中的 ObjectiveC Bridging 标题行中添加
projectname/bridgingheaderfilename
然后您可能还需要清理构建文件夹(产品菜单,按住选项键)。
关于ios - 是否有任何示例/示例可用于使用适用于 iOS 的 Google People API?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50129233/