- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以一切正常,我喜欢这个 sdk,但是当我推送 auth Controller 时:
GTMOAuth2ViewControllerTouch *authController;
authController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:kGTLAuthScopeDrive
clientID:kClientID
clientSecret:kClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
[self.navigationController pushViewController:authController animated:YES];
然后在不输入用户电子邮件和密码的情况下返回委托(delegate)回调返回错误:
The operation couldn’t be completed. (com.google.GTMOAuth2 error -1000.)
但是我不确定代理是否应该为我返回这个错误。我使用了快速入门示例。
我的问题是它为什么返回错误,这是正确的吗?因为我只是从 auth Controller 弹出回到以前的 Controller ,所以没有任何犯罪行为,我不想处理任何 api 调用。
最佳答案
当窗口过早关闭时,委托(delegate)方法在 NSError
参数中返回错误代码 -1000
。
这个error.code
(-1000
) 没什么好担心的,它可以让你看到用户做了什么。如果他们确实在未经授权的情况下返回,您可能需要显示一条消息“您没有授权,您应该使用我们的 Google 强大功能!”,或者您可以简单地忽略它。。。 p>
来自:/Project/Pods/gtm-oauth2/GTMOAuth2Authentication.h
enum {
// Error code indicating that the window was prematurely closed
kGTMOAuth2ErrorWindowClosed = -1000,
kGTMOAuth2ErrorAuthorizationFailed = -1001,
kGTMOAuth2ErrorTokenExpired = -1002,
kGTMOAuth2ErrorTokenUnavailable = -1003,
kGTMOAuth2ErrorUnauthorizableRequest = -1004
};
适用于新 iOS 开发人员的简单示例。 ( Google's documentation is also fantastic )
使用(例如:子集 /Drive
)通过 CocoaPods 安装 Google API:
pod 'Google-API-Client/Drive'
在您的 View Controller 中,添加以下变量:
// access keys (Should be in a seperate class or constants file)
#define kKeychainItemName @"Google Drive Quickstart"
#define kGDClientID @"your-client-id"
#define kGDClientSecret @"your-client-secret"
@interface ClassViewController() {
GTMOAuth2ViewControllerTouch *_authController; // Auth v/c
YourCustomGoogleDriveController *_googleDriveController; // Custom Class
}
接下来我们需要一个方法来创建和返回我们的 Google OAuth2 View Controller
,将其添加到同一个类中。
/**
* Create a new instance of our google auth view controller
*/
- (GTMOAuth2ViewControllerTouch *)createAuthController
{
_authController = [[GTMOAuth2ViewControllerTouch alloc] initWithScope:kGTLAuthScopeDrive
clientID:kClientID
clientSecret:kClientSecret
keychainItemName:kKeychainItemName
delegate:self
finishedSelector:@selector(viewController:finishedWithAuth:error:)];
return _authController;
}
当上面的委托(delegate)方法完成后,它会调用下面的函数(注意上面函数中的delegate: self
和@selector
)。
/**
* Our delegate method, always called, either with auth token or error
*/
- (void)viewController:(GTMOAuth2ViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuth2Authentication *)authResult
error:(NSError *)error
{
if (error != nil) {
// We have some sort of error, handle it or ignore
_googleDriveController.driveService.authorizer = nil;
switch (error.code) {
case kGTMOAuth2ErrorWindowClosed:
// Show a message? : "Sign in for awesomeness!"
NSLog(@"%ld: User closed window prematurely", (long)error.code);
break;
case kGTMOAuth2ErrorAuthorizationFailed:
NSLog(@"%ld: Authorization Failed", (long)error.code);
break;
case kGTMOAuth2ErrorTokenExpired:
NSLog(@"%ld: Token Expired", (long)error.code);
break;
case kGTMOAuth2ErrorTokenUnavailable:
NSLog(@"%ld: Token Unavailable", (long)error.code);
break;
case kGTMOAuth2ErrorUnauthorizableRequest:
NSLog(@"%ld: Unauthorizable Request", (long)error.code);
break;
default:
break;
}
} else {
// Set the result into our `GTLServiceDrive` in our Custom Controller
_googleDriveController.driveService.authorizer = authResult;
NSLog(@"Success! - User Auth'ed!");
}
}
最后我们需要一个 IBAction 或其他东西来调用我们上面的代码:
/**
* Create our auth controller, and push it to the nav stack (assuming we are in one)
*/
- (IBAction)someButtonClicked:(id)sender
{
[self createAuthController]; // Init our auth controller
_authController.title = @"Sign in"; // Set a custom title (if you want)
[self.navigationController pushViewController:_authController animated:YES];
//[self presentViewController:controller animated:YES completion:nil]; // Show Modally
}
关于iOS 谷歌驱动器 API。操作无法完成。 (com.google.GTMOAuth2 错误 -1000。),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23280558/
我执行以下操作以检查远程计算机上的本地驱动器/分区: Get-WmiObject -Class Win32_Share -ComputerName SERVERNAME -Filter "Descri
我正在尝试扫描包含成千上万个文件的共享网络驱动器,仅查找过去一年中未修改的Word文件。虽然我写的东西行得通,但速度非常慢。我需要扫描多个驱动器,这需要几个小时。我有什么办法可以加快速度? gci \
我记得在 vb6 中有一个类似于 dropbox/combobox 的控件,您可以选择驱动器名称。它会引发一个事件,然后您可以设置另一个控件来枚举列表框中的文件。 (在 drive.event 中你做
USB 驱动器有哪些安全风险? USB 驱动器优点是体积小、容易获得、价格低廉且便于携带,因此在将文件从一台计算机存储和传输到另一台计算机方面很受欢迎。然而,这些优点特征使它们对攻击者具有吸引
驱动器的编程对黑客编程来说至关重要。好在vbs给我们提供了方便的集合,使得工作变得很简单。 1、检查驱动器 使用filesy
我正在尝试编写批处理文件以将文件夹xcopy到可移动USB驱动器。但是,我面临的问题是驱动器号可能会发生变化,因此我希望能够通过引用卷标而不是驱动器号来做到这一点。 有任何想法吗?一个小时的Googl
我正在用 C# 开发一个应用程序,因此,如果用户确认消息框格式化 USB 驱动器,从组合框列表中选择,驱动器将被格式化。 我不知道如何处理这个问题,但是 - 我有以下代码: public stati
我正在尝试将文件保存到 icloud 驱动器。我会选择简单的版本,我不让用户选择保存文件的位置,我只是将它保存在 icloud 驱动器的根目录中。这是我正在使用的代码: func exportToFi
我正在尝试创建一个脚本,我将在其中搜索文件服务器的非继承权限。结果,我遇到了文件名 260 个字符的限制。我看到的一个建议,我认为会有所帮助,有几次是创建一些非持久性的 PS 驱动器,深度为几个级别并
我正在制作一个 USB 驱动器,其中应包含有助于解决用户遇到的各种软件问题的工具。 您建议我添加哪些工具? 主要环境:Windows和.NET 最佳答案 我可以推荐以下内容:{其中一些已经被提及} 日
因此,在稀缺的introduction to inegration testing中,您应该使用 flutter drive --target=test_driver/app.dart 但是我找不到有
我正在尝试让 docker 挂载我的 d 驱动器。一直在与大量的 stack 和 git 作斗争,但它们似乎都不适合我。 我已经将我的d盘添加到共享文件夹 然后我安装在我的 docker-compos
我正在尝试以编程方式从 Powershell 应用程序中安全地删除 USB 驱动器。我当前的代码适用于单卷 USB 驱动器。代码如下: $Eject = New-Object -comObject S
我有一个乏味的项目即将到来。我需要将 USB 闪存驱动器插入计算机,然后将三个文件复制到该驱动器,然后卸载它并重复 3000 次(字面意思)。我希望能想出一些 VBScript 来减少我的 Actio
我正在编写一个提取 xml 的文件以获取文件名,并且需要将这些文件复制到 USB 驱动器。前两个步骤我能够做到这一点。但问题是: 如何检测是否有 U 盘 然后检测它是哪个驱动器。 谢谢! 最佳答案 这
在我的 Java Web 应用程序中,需要单击“保存文件”按钮将 6 个文件从服务器复制到用户计算机 USB 驱动器。 如果未找到 USB 驱动器,则需要显示警告消息“未检测到 USB 驱动器”。 我
您好,我有以下查询来获取 12 个月前的时间窗口内每月发生的驱动器。然而,结果并不正确,例如,在我的测试数据库中,2 月份仅发生了 3 个驱动器,但在我的结果集中,它显示了 9 个驱动器。 SELEC
我一直在尝试找到一种通过 swift 2 和 Xcode 7 连接到我的网络驱动器的方法。我可以连接到我的桌面或文档目录,但不能连接到我的服务器。我玩过 NSString/NSURL 等但无济于事。以
我有几个问题: 以下 C++ 代码是否会导致我的硬盘在经过一定时间后空闲? #include int main() { while(1); } 如果是这样,我可以在此代码中添加什么以确保我的
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
我是一名优秀的程序员,十分优秀!