I've been working on this for over a day so now asking for help! I'm trying to write an iOS app that authenticates using a google service account in order to access Google storage.
I can't get beyond this error which occurs at the authoriseRequest and when trying to create a bucket.
Error Domain=com.google.GTMOAuth2 Code=-1001 "The operation couldn’t be completed. (com.google.GTMOAuth2 error -1001.)" UserInfo=0x15640740 {request= { URL: https://www.googleapis.com/rpc?prettyPrint=false }}
It's my first time working with the google objective c libraries and almost all of the examples that I've found online, and in stackOverflow are aimed at using GTMOAuth2ViewControllerTouch, but I'm not authenticating from the user
So far, I've gotten this.
Before my init ..
static GTLServiceStorage *storageService = nil;
static GTMOAuth2Authentication *auth;
In my init ..
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;
}
And in a method to create a bucket for example..
// 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);
}];
My question is, am I using the gtmoauth2 library correctly for a service account authentication, and if so am I missing something obvious in my parameters or my initialisation.
Thanks