是否有任何示例/示例可用于iOS的Google People API? [英] Is there any sample/example available to use Google People API for iOS?
问题描述
我仔细阅读了他关于Google People API的文档.
I went through he documentation for Google People API.
https://developers.google.com/people/v1/getting-started
我找不到任何帮助/示例来为iOS平台实现相同的功能.iOS平台有可用的帮助吗?
I couldn't find any help/sample to implement the same for iOS platform. Is there any help available for iOS platform?
推荐答案
是的,有适用于iOS的People API客户端库.要指定它,请指定
Yes there is a People API client library for iOS. To include it you specify
pod 'GoogleAPIClientForREST/PeopleService', '~> 1.3.4'
pod 'GoogleSignIn', '~> 4.1.2'
在Cocoapods pod文件中.
in the Cocoapods pod file.
否,除了源库本身位于 https://github.com/google/google-api-objectivec-client-for-rest
No, I havn't found any documentation of the Google People API client library for iOS except the source libraries themselves at https://github.com/google/google-api-objectivec-client-for-rest
使用Google Calendar API iOS Swift示例代码作为指导,进行设置
Use the Google Calendar API iOS Swift sample code as guidance, setting
private let scopes = [kGTLRAuthScopePeopleServiceContactsReadonly]
private let service = GTLRPeopleServiceService()
以下代码读取已登录用户的联系人列表.
The following code reads the contacts list for the signed in user.
// 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示例构建没有错误,您可能需要添加桥接头文件(文件">新建">文件",选择头文件)并添加以下内容:
ps To make the Google Calendar API iOS Swift sample build without errors, you probably need to add a bridging header file (File > New > File, choose header file) and add the following:
#import <GTMSessionFetcher/GTMSessionFetcher.h>
#import <GTMSessionFetcher/GTMSessionFetcherService.h>
然后在Swift Compiler-General标题下的目标Build Settings中,在ObjectiveC Bridging标题行中添加
Then in the target Build Settings under the Swift Compiler - General heading, in the ObjectiveC Bridging header row add
projectname/bridgingheaderfilename
然后,您可能还需要清理构建文件夹(产品"菜单,按住选项键).
You may also then have to clean the build folder (Product menu, hold down options key).
这篇关于是否有任何示例/示例可用于iOS的Google People API?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!