Nir*_*raj 3 ios swift google-people-api
我浏览了 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'
Run Code Online (Sandbox Code Playgroud)
在 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()
Run Code Online (Sandbox Code Playgroud)
以下代码读取已登录用户的联系人列表。
// 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 ?? "")
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
ps 要使 Google Calendar API iOS Swift 示例构建没有错误,您可能需要添加桥接头文件(文件 > 新建 > 文件,选择头文件)并添加以下内容:
#import <GTMSessionFetcher/GTMSessionFetcher.h>
#import <GTMSessionFetcher/GTMSessionFetcherService.h>
Run Code Online (Sandbox Code Playgroud)
然后在 Swift Compiler - General 标题下的目标 Build Settings 中,在 ObjectiveC Bridging 标题行中添加
projectname/bridgingheaderfilename
Run Code Online (Sandbox Code Playgroud)
然后您可能还必须清理构建文件夹(产品菜单,按住选项键)。
| 归档时间: |
|
| 查看次数: |
1614 次 |
| 最近记录: |