我从以下路径获得了用于 Objective C 的 Google API,用于使用云存储模块。
不幸的是,该 api 没有为云存储提供任何示例代码,所以我尝试自己做,但我无法成功。下面是我在做什么
- 我从 Google API 控制台启用了 Cloud Storage 计费
- 我做了一个名为“ahs_test”的桶
- 我为已安装的应用程序创建了一个客户端 ID
- 我在 Outh2.0 上取得了成功,并在上层 SVN 路径提供了库。这样做之后,我写了下面的代码并得到下面的错误消息
- 请注意,在阅读了 Google Cloud Storage 之后,我有点确定我必须在我的请求标头中发送“x-goog-project-id”,但我想知道这个 API 的代码没有做类似的事情。(我可能会犯一些错误,所以留下这个以获得任何帮助......在此先感谢......)
// Code....
GTLServiceStorage *service = self.storageService
GTLQueryStorage *query = [GTLQueryStorage queryForBucketsGetWithBucket:@"ahs_test"];
_fileListTicket = [service executeQuery:query
completionHandler:^(GTLServiceTicket *ticket,
GTLStorageBuckets *bucketList,
NSError *error) {
}];
// Error Message I get (Detailed from loger)
storage.buckets.get
2012-12-30 07:11:30 +0000
Request: POST https://www.googleapis.com/rpc?prettyPrint=false
Request headers:
Accept: application/json-rpc
Authorization: Bearer _snip_
Cache-Control: no-cache
Content-Type: application/json-rpc; charset=utf-8
User-Agent: com.example.DriveSample/1.0 google-api-objc-client/2.0 MacOSX/10.8 (gzip)
Request body: (128 bytes)
{
"jsonrpc" : "2.0",
"method" : "storage.buckets.get",
"id" : "gtl_3",
"params" : {
"bucket" : "ahs_test",
"max-results" : 150
},
"apiVersion" : "v1beta1"
}
Response: status 200
Response headers:
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Content-Encoding: gzip
Content-Length: 132
Content-Type: application/json; charset=UTF-8
Date: Sun, 30 Dec 2012 07:10:44 GMT
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Pragma: no-cache
Server: GSE
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Response body: (168 bytes)
{
"error" : {
"message" : "Access Not Configured",
"data" : [
{
"reason" : "accessNotConfigured",
"message" : "Access Not Configured",
"domain" : "usageLimits"
}
],
"code" : 403
},
"id" : "gtl_3"
}