我正在尝试导入 GoogleAPIClient 或 GoogleAPIClientForREST

2024-04-17

我正在努力追随谷歌的教程 https://developers.google.com/drive/ios/quickstart?ver=swift制作他们的 QuickStart 应用程序来学习如何使用 Swift 进行 API 调用。我完全按照教程进行操作并最终得到了这段代码

import GoogleAPIClient
import GTMOAuth2
import UIKit

class ViewController: UIViewController {

    private let kKeychainItemName = "Drive API"
    private let kClientID = "592019061169-nmjle7sfv8i8eahplae3cvto2rsj4gev.apps.googleusercontent.com"

    // If modifying these scopes, delete your previously saved credentials by
    // resetting the iOS simulator or uninstall the app.
    private let scopes = [kGTLAuthScopeDriveMetadataReadonly]

    private let service = GTLServiceDrive()
    let output = UITextView()

    // When the view loads, create necessary subviews
    // and initialize the Drive API service
    override func viewDidLoad() {
        super.viewDidLoad()

        output.frame = view.bounds
        output.editable = false
        output.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0)
        output.autoresizingMask = [.FlexibleHeight, .FlexibleWidth]

        view.addSubview(output);

        if let auth = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName(
            kKeychainItemName,
            clientID: kClientID,
            clientSecret: nil) {
            service.authorizer = auth
        }

    }

    // When the view appears, ensure that the Drive API service is authorized
    // and perform API calls
    override func viewDidAppear(animated: Bool) {
        if let authorizer = service.authorizer,
            let canAuth = authorizer.canAuthorize, canAuth {
            fetchFiles()
        } else {
            presentViewController(
                createAuthController(),
                animated: true,
                completion: nil
            )
        }
    }

    // Construct a query to get names and IDs of 10 files using the Google Drive API
    func fetchFiles() {
        output.text = "Getting files..."
        let query = GTLQueryDrive.queryForFilesList()
        query.pageSize = 10
        query.fields = "nextPageToken, files(id, name)"
        service.executeQuery(
            query,
            delegate: self,
            didFinishSelector: "displayResultWithTicket:finishedWithObject:error:"
        )
    }

    // Parse results and display
    func displayResultWithTicket(ticket : GTLServiceTicket,
                                 finishedWithObject response : GTLDriveFileList,
                                 error : NSError?) {

        if let error = error {
            showAlert("Error", message: error.localizedDescription)
            return
        }

        var filesString = ""

        if let files = response.files(), !files.isEmpty {
            filesString += "Files:\n"
            for file in files as! [GTLDriveFile] {
                filesString += "\(file.name) (\(file.identifier))\n"
            }
        } else {
            filesString = "No files found."
        }

        output.text = filesString
    }


    // Creates the auth controller for authorizing access to Drive API
    private func createAuthController() -> GTMOAuth2ViewControllerTouch {
        let scopeString = scopes.joinWithSeparator(" ")
        return GTMOAuth2ViewControllerTouch(
            scope: scopeString,
            clientID: kClientID,
            clientSecret: nil,
            keychainItemName: kKeychainItemName,
            delegate: self,
            finishedSelector: "viewController:finishedWithAuth:error:"
        )
    }

    // Handle completion of the authorization process, and update the Drive API
    // with the new credentials.
    func viewController(vc : UIViewController,
                        finishedWithAuth authResult : GTMOAuth2Authentication, error : NSError?) {

        if let error = error {
            service.authorizer = nil
            showAlert("Authentication Error", message: error.localizedDescription)
            return
        }

        service.authorizer = authResult
        dismissViewControllerAnimated(true, completion: nil)
    }

    // Helper for showing an alert
    func showAlert(title : String, message: String) {
        let alert = UIAlertController(
            title: title,
            message: message,
            preferredStyle: UIAlertControllerStyle.Alert
        )
        let ok = UIAlertAction(
            title: "OK",
            style: UIAlertActionStyle.Default,
            handler: nil
        )
        alert.addAction(ok)
        presentViewController(alert, animated: true, completion: nil)
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

我的问题是对于

import GoogleAPIClient

我收到错误“没有这样的模块 GoogleAPIClient”,这对我来说很奇怪,因为 GTMOAuth2 没有收到错误,即使它是我认为的同一个 Pod 的一部分(我对此很陌生,所以我可能正在破坏术语)。

通过研究这个问题,我发现 GoogleAPIClientForREST 应该替换 GoogleAPIClient。GitHub 上的此文档 https://github.com/google/google-api-objectivec-client-for-rest/wiki/BuildingTheLibrary说只在代码中使用 GoogleAPIClientForREST 而不是 GoogleAPIClient,但我也遇到了同样的错误。

然后我想也许我可以重新安装 Pod,并对 Google 的教程进行一些更改。在教程中,它说在终端中执行此代码

$ cat << EOF > Podfile &&
> platform :ios, '7.0'
> use_frameworks!
> target 'QuickstartApp' do
>     pod 'GoogleAPIClient/Drive', '~> 1.0.2'
>     pod 'GTMOAuth2', '~> 1.1.0'
> end
> EOF
> pod install &&
> open QuickstartApp.xcworkspace

所以我想也许我可以在终端代码中将 GoogleAPIClient 替换为 GoogleAPIClientForREST,但这给我带来了同样的错误

正如您在屏幕截图中看到的,框架位于左侧,但我仍然收到“没有这样的模块”错误。

嵌入式二进制文件和链接框架

搜索路径

I also found some suggestions here https://stackoverflow.com/a/38182451/7120487 that I tried to follow, but I didn't completely understand the explanation. Nevertheless, I tried, and did this (if I did it wrong please tell me): enter image description here

所以我试图让 GoogleAPIClient 或 GoogleAPIClientForREST 工作。感谢您的帮助


将其用于您的 Podfile:

platform :ios, '7.0'
use_frameworks!
target 'QuickstartApp' do
    pod 'GoogleAPIClientForREST/Drive', '~> 1.1.1'
    pod 'GTMOAuth2', '~> 1.1.0'
end

将您的导入更改为

import GoogleAPIClientForREST

然后按照此处的说明迁移项目:从 GoogleAPIClient 迁移到 GoogleAPIClientForREST https://github.com/google/google-api-objectivec-client-for-rest/wiki/Migrating-From-GTL-to-GTLR

这主要涉及通过一些字交换将 GTL 调用更改为 GTLR 调用。例如,GTLServiceDrive变成GTLRDriveService.

关于框架搜索路径,此图显示了您可能需要更改的部分(请注意,它适用于我使用默认值):

搜索路径也可以针对每个目标。这是显示应用程序目标和框架搜索路径的图像:

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我正在尝试导入 GoogleAPIClient 或 GoogleAPIClientForREST 的相关文章

  • AVCaptureDevice isFlashModeSupported 已弃用 iOS 10

    我正在使用 AVCaptureDevice 的实例方法 isFlashModeSupported 如下所示 NSArray captureDeviceType AVCaptureDeviceTypeBuiltInWideAngleCamer
  • Python BigQuery 超时确实很奇怪

    我正在构建一项将数据流式传输到 bigquery 的服务 如果我删除需要 4 5 分钟加载的部分 我正在预缓存一些映射 则以下代码可以完美运行 from googleapiclient import discovery from oauth
  • 如何在 Swift 中打开 URL?

    openURL已在 Swift 3 中弃用 任何人都可以提供一些如何替换的示例openURL options completionHandler 尝试打开网址时有效吗 所有你需要的是 guard let url URL string htt
  • 如何在本地闭包中调用非逃逸闭包? [复制]

    这个问题在这里已经有答案了 我有一个看起来像这样的函数 func test closure gt let localClosure closure localClosure 这只是一个例子 并不能完全反映我遇到的问题 显然在这里我可以直接打
  • GoogleCalendarAPI 接受/拒绝事件

    我正在研究谷歌日历API并使用node js作为构建我的应用程序的平台 我能够使用身份验证过程创建事件 并使用身份验证时生成的访问令牌创建日历事件 我的问题是 假设如果我们有任何参加者参加活动 并且我想使用参加者一方的日历 API 接受 拒
  • 为什么viewDidLoad在swift中完成后没有显示数据? [关闭]

    Closed 这个问题需要调试细节 help minimal reproducible example 目前不接受答案 当我的应用程序启动完成后 UITableViewCell 上应该显示数据 但是 那里什么也没有 所以重新启动应用程序后
  • Swift 3 - 扩展字典数组

    我有这一系列字典 var dicts key1 value1 key2 value2 key1 value3 key2 value4 我应该如何延长Array这样我就有这个功能 dicts values of key1 result val
  • Swift 3 / Xcode 8 升级 - 工作副本错误导致 100 个 DerivedData 文件丢失

    我刚刚升级到 XCode 和 Swift 的最新 Beta 版本 但使用转换器后 我的应用程序项目现在有超过 200 个构建时黄色错误 所有错误均指出 projectDirectoy DerivedData XXXXXXXXX XXXX X
  • 从 Google Chat POST 请求验证 JWT

    我有一个 NodeJS 机器人使用 HTTPs 端点连接到 Google Chat 我正在使用快递来接收请求 我需要验证所有请求是否都来自 Google 并且希望使用 Google 随请求发送的不记名令牌来执行此操作 我的问题是我正在努力寻
  • Linux 中的 Swift arc4random_uniform(max)

    我在 Ubuntu 中使用 Swift 收到一条错误消息 指出 arc4random 是一个无法解析的标识符 有关此已知错误的更多信息here https bugs swift org browse SR 685 基本上 该功能仅存在于 B
  • 如何在Python程序中嵌入Google Speech to Text API? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我有一个项目 在其中创建了客户端和主机之间的聊天程序 并且我必须在其中嵌入语音到文本 有什么方法可以在
  • 在 Swift 3 中从 UUID 获取数据

    我用 Objective C 编写了以下代码 我试图在 Swift 3 中使用它 一些等效函数似乎在 Swift 3 中不可用 下面的代码是 Objective C 中的代码 NSUUID vendorIdentifier UIDevice
  • 使用未解析的运算符 <=

    我正在尝试使用 Swift 3 for 循环 但没有成功 这是我所拥有的 for assumedPayRate Double in 0 25 lt billRate where assumedPayRate 0 25 On the lt 它
  • 如何使用 ASP.Net Core Identity 从登录用户检索 Google 个人资料图片?

    好的 我目前正在使用 ASP NET Core 1 1 2 和 ASP NET Core Identity 1 1 2 其中重要的部分是启动 cs看起来像这样 public void Configure IApplicationBuilde
  • 在 WooCommerce 3.3 中使用 Google Map API 计算结帐距离

    我已经发布几个月前有类似的问题 https stackoverflow com questions 46348735 calculated distance shipping cart fee via google api in wooco
  • 如何将媒体附件添加到 iOS 10 应用程序中的推送通知中?

    有多个示例 您应该如何设置项目来添加使用 媒体附件 技术来显示图像的丰富通知 我已经阅读了其中的大部分内容 但我错过了一些内容 因为我的项目没有使用此有效负载显示任何丰富的通知 使用 APNS Tool 和 Boodle 进行测试 aps
  • 如何执行条件segue

    我通过 IB 创建了一个 segue 单击按钮时 将转换到视图 A 在按钮单击操作中 我有performSegue withIdentifier sender 包裹在一个条件中 我希望仅当条件为真时才发生 segue 但是 一旦用户单击按钮
  • 有 Google Keep API 吗? [关闭]

    Closed 此问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 Google Keep 有 API 吗 我想为 Google Keep 制作一个 Windows 8 应
  • Swift 3 中的 NSFetchedResultsController 删除缓存

    目前正在迁移到 swift 3 无法完全弄清楚解析器想要什么NSFetchedResultsController deleteCache withName rootCache 使用这种语法 我得到一个 Type String 构建时出现不符
  • 使用 Swift 3 和 Realm 同步 Apple Watch 和 iPhone

    我需要从 Apple Watch 和 iPhone 显示和修改我的数据结构 数据库 我目前正在使用一个简单的领域结构 其中有一个对象 A 和一个可以容纳大量 A 的对象 B 因此 在 iPhone 上 用户可以创建 B 并添加 A 当然还可

随机推荐

  • 在 Entity Framework Core 中使用 SQL 视图

    例如 我有这样的模型 public class Blog public int BlogId get set public string Url get set public BlogImage BlogImage get set publ
  • 具有多个服务器的计划任务 - 单点责任

    我们有一个 Spring JPA Web 应用程序 我们使用两个运行应用程序并使用相同数据库的 tomcat 服务器 您的应用程序要求之一是执行 cron 计划任务 经过简短的研究 我们发现 Spring 框架为 cron 作业提供了一个非
  • Struts2中ActionMapper、ActionProxy、ActionInitation、ActionContext对象的范围?

    任何人都可以描述一下我的对象吗 ActionMapper ActionProxy ActionInvocation ActionContext在 Struts2 应用程序中创建 由于我是 Struts2 框架的新手 我对这些对象的范围感到非
  • AWS ElasticSearch:如何将策略应用于索引

    我们有一个 AWS ElasticSearch 域 正在向其中写入记录 文档 我现在已经在 Kibana 中创建了索引状态 生命周期管理 ISM ILM 策略 并且可以将该策略应用于 Kibana 中的索引 现在 我想在从处理索引写入的 J
  • 从 Roslyn ClassDeclarationSyntax 获取类 FullName(包括命名空间)

    我有一个来自 roslyn 语法树的 ClassDeclarationSyntax 我是这样读的 var tree SyntaxTree ParseText sourceCode var root CompilationUnitSyntax
  • d3.event 在去抖动函数内为 null

    当尝试使用 mousemove 事件处理程序的去抖版本时 d3 event is null 我想使用d3 mouse此去抖动处理程序中的对象 但是d3 event返回 null 并抛出错误 我怎样才能访问d3 event在下面的代码中 a
  • 匹配两个不同文件中最接近的值并打印特定列

    大家好 我有两个文件 每个文件都有 N 列和 M 行 File1 1 2 4 6 8 20 4 8 10 12 15 5 7 9 11 File2 1 a1 b1 c5 d1 2 a1 b2 c4 d2 3 a2 b3 c3 d3 19 a
  • 如何在 C# 中获得正确的 HTML 编码?

    我正在尝试从网络词典中获取某个单词的发音 例如 在下面的代码中 我想得到的发音good from http collinsdictionary com http collinsdictionary com HTTP Agility Pack
  • 如何统计SVN分支中更改或添加的行数?

    我想将 SVN 分支中的行更改数量相加 这样我就可以从另一方知道我在项目过程中走了多远 并估计当我将其与主干合并时发生冲突的概率 我能想到的方法是获取统一的 diff 并进行一些 grep wc l hack 但问题是很难分离不同的文件类型
  • 进程退出的问题

    假设我有一个 ID 为 1234 的进程 该进程在我的应用程序运行之前运行 我有这个代码 Process app Process GetProcessById 1234 MessageBox Show app MainWindowTitle
  • WINAPI_FAMILY_PARTITION 有何作用?

    我正在阅读头文件的定义winapifamily h并注意以下定义WINAPI FAMILY PARTITION define WINAPI FAMILY PARTITION Partitions Partitions 该宏的一般用法 作为示
  • 我们可以在javascript中将对象分配给cookie吗?

    有谁知道是否可以在javascript中将一个对象分配给cookies 如果是的话 我们该怎么做呢 如果您可以将对象序列化为其规范的字符串表示形式 并且可以将其从所述字符串表示形式反序列化回其对象形式 那么您可以将其放入 cookie 中
  • 从空整数到逗号列表中的指针的转换

    我知道在我们的现代世界中 NULL 和 0 并不是指针操作的最佳实践 根据 cppreference 指针转换 空指针常量 参见 NULL 可以是 转换为任意指针类型 结果为空指针 该类型的值 这种转换 称为空指针转换 允许作为单个转换转换
  • Activator.CreateInstance 找不到构造函数(MissingMethodException)

    我有一个具有以下构造函数的类 public DelayCompositeDesigner DelayComposite CompositeObject InitializeComponent compositeObject Composit
  • 如果 URL 以 https:// 开头,则不会显示网站图标

    我在使用 favicon ico 时遇到一个问题 这是我的链接相关代码 已包含在标头部分中 问题是 如果 url 以 http 开头 我可以在所有浏览器中查看该图标 当地址以 https 开头时 图标不会在 IE 浏览器中显示 有什么我需要
  • OpenGL固定功能着色器实现[关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 是否有任何包装器可以在 OpenGL ES 2 0 之上模拟 OpenGL ES 1 1 API 我进
  • iOS8 - 模拟器 - 如何模拟位置

    我的应用程序跟踪您的位置 对于 iOS8 我必须改变它启动位置服务的方式 我得到了这个工作 self locationManager requestAlwaysAuthorization 并将 NSLocationAlwaysUsageDe
  • 从当前日期减去月份 sql

    我正在尝试从今天减去日期 获取 1 个月前直到永远的报告 到目前为止我已经尝试过 DATE SUB NOW INTERVAL 1 MONTH 这是上下文 SELECT contracts currency ROUND SUM CASE WH
  • 如何将 Google Analytics 跟踪 ID 添加到 GitHub Pages

    可能是一个简单的问题 但我现在对添加充满疑问谷歌分析跟踪ID to GitHub 页面 我正在使用 GitHub 自动页面生成器来创建我的 GitHub 页面 但它要求提供 Google Analytics 跟踪 ID 我尝试注册 Goog
  • 我正在尝试导入 GoogleAPIClient 或 GoogleAPIClientForREST

    我正在努力追随谷歌的教程 https developers google com drive ios quickstart ver swift制作他们的 QuickStart 应用程序来学习如何使用 Swift 进行 API 调用 我完全按