我使用Google Cloud Storage API for obj-c将数据插入存储桶,但我收到了400服务器错误:
{原因:" keyInvalid"消息:"错误请求"域:" usageLimits"}
我使用服务帐户身份验证方法,将GTLServiceStorage的APIKey属性设置为开发人员控制台生成的密钥值,据我所知,我不需要OAuth2身份验证的访问令牌?
我已经为各个领域尝试了几种组合而没有运气。代码如下所示:
_serviceStorage = [GTLServiceStorage new];
_serviceStorage.additionalHTTPHeaders = @{@"x-goog-project-id": LTProjectID};
_serviceStorage.APIKey = ServiceAccountAPIKeyFromJsonKey;
GTLUploadParameters *uploadParam
= [GTLUploadParameters uploadParametersWithData:data MIMEType:@"audio/mp4"];
GTLStorageObject *storageObj = [GTLStorageObject object];
storageObj.name = @"file_name"
GTLStorageObjectAccessControl *objAccessControl
= [GTLStorageObjectAccessControl new];
objAccessControl.entity = @"allUsers";
objAccessControl.email = @"5942472xxxxxxx@developer.gserviceaccount.com";
objAccessControl.role = @"OWNER";
storageObj.acl = @[objAccessControl];
GTLQueryStorage *query
= [GTLQueryStorage queryForObjectsInsertWithObject:storageObj
bucket:@"my_bucket"
uploadParameters:uploadParam];
GTLServiceTicket *ticket
= [_serviceStorage executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
id object,
NSError *error) {
// error: {reason:"keyInvalid" message:"Bad Request" domain:"usageLimits"}
}
}];
ticket.uploadProgressBlock ...