Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用GTMOAuth2通过谷歌存储验证iOS的困难_Ios_Google Cloud Storage_Gtm Oauth2 - Fatal编程技术网

使用GTMOAuth2通过谷歌存储验证iOS的困难

使用GTMOAuth2通过谷歌存储验证iOS的困难,ios,google-cloud-storage,gtm-oauth2,Ios,Google Cloud Storage,Gtm Oauth2,我已经为此工作了一天多,所以现在请求帮助!我正在尝试编写一个iOS应用程序,它使用google服务帐户进行身份验证,以便访问google存储 我无法超越在授权请求和尝试创建bucket时发生的错误 错误域=com.google.GTMOAuth2代码=-1001“操作无法完成。(com.google.GTMOAuth2错误-1001。)”用户信息=0x15640740{request={URL:} 这是我第一次使用google objective c库,我在网上和stackOverflow中找到

我已经为此工作了一天多,所以现在请求帮助!我正在尝试编写一个iOS应用程序,它使用google服务帐户进行身份验证,以便访问google存储

我无法超越在授权请求和尝试创建bucket时发生的错误

错误域=com.google.GTMOAuth2代码=-1001“操作无法完成。(com.google.GTMOAuth2错误-1001。)”用户信息=0x15640740{request={URL:}

这是我第一次使用google objective c库,我在网上和stackOverflow中找到的几乎所有示例都是针对使用GTMOAuth2ViewControllerTouch的,但我不是从用户那里进行身份验证

到目前为止,我已经知道了

在我开始之前

static GTLServiceStorage *storageService = nil;
static GTMOAuth2Authentication *auth;
auth = [ GTMOAuth2SignIn standardGoogleAuthenticationForScope:@"kGTLAuthScopeStorageDevstorageFullControl" clientID:@"my_client_id.apps.googleusercontent.com" clientSecret:@"my_client_secret"];
auth.redirectURI = @"urn:ietf:wg:oauth:2.0:oob";
// inititialising the auth token
[auth authorizeRequest:nil  delegate:self didFinishSelector:@selector(authentication:request:finishedWithError:)];

// init googleStorage Backend service.
if (!storageService) {
    storageService = [[GTLServiceStorage alloc] init];
    storageService.additionalHTTPHeaders = @{@"x-goog-project-id": @"my_project_id", @"Content-Type": @"application/json-rpc", @"Accept":
                                                 @"application/json-rpc"};
    storageService.authorizer = auth;
    storageService.retryEnabled = YES;
}
在我看来

static GTLServiceStorage *storageService = nil;
static GTMOAuth2Authentication *auth;
auth = [ GTMOAuth2SignIn standardGoogleAuthenticationForScope:@"kGTLAuthScopeStorageDevstorageFullControl" clientID:@"my_client_id.apps.googleusercontent.com" clientSecret:@"my_client_secret"];
auth.redirectURI = @"urn:ietf:wg:oauth:2.0:oob";
// inititialising the auth token
[auth authorizeRequest:nil  delegate:self didFinishSelector:@selector(authentication:request:finishedWithError:)];

// init googleStorage Backend service.
if (!storageService) {
    storageService = [[GTLServiceStorage alloc] init];
    storageService.additionalHTTPHeaders = @{@"x-goog-project-id": @"my_project_id", @"Content-Type": @"application/json-rpc", @"Accept":
                                                 @"application/json-rpc"};
    storageService.authorizer = auth;
    storageService.retryEnabled = YES;
}
例如,在创建bucket的方法中

// Create a GTLStorageBucket.
GTLStorageBucket* bucket = [[GTLStorageBucket alloc] init];
bucket.name = @"myBucketName";
// Create the query
GTLQueryStorage *query = [GTLQueryStorage queryForBucketsInsertWithObject:bucket project:@"myGoogleProjectID"];
[storageService executeQuery:query completionHandler:^(GTLServiceTicket *ticket, GTLStorageBucket  *object, NSError *error) {
    NSLog(@"bucket %@", object);
}];
我的问题是,我是否正确地使用gtmoauth2库进行服务帐户身份验证,如果是,我的参数或初始化中是否遗漏了一些明显的内容


谢谢

问题可能是
kGTLAuthScopeStorageDevstorageFullControl
是一个常量,通过将其放入@“”,您创建的NSString字面上是“kGTLAuthScopeStorageDevstorageFullControl”,它与该方法可能期望的常量值不相等。

不幸的是,根据讨论组的说法,Google API Objective C库中不支持服务帐户,因为Objective C库仅用于构建客户端应用程序:


我想这可能就是你找到的答案了吗?@sti恐怕我实际上已经无法访问该代码库了,但我很确定我没有解决这个问题,最终放弃使用GTLQueryStorageGoogle服务帐户身份验证通常需要证书,如果我没有弄错的话。客户端ID/客户端机密不够。但是,我在gtm-oauth2库中找不到用于指定证书的接口。有人知道吗?也许应该使用标准苹果安全框架中的对象?