我正在使用swift對我的谷歌雲存儲桶進行API調用。Google雲端存儲 - 匿名用戶沒有storage.buckets.list項目訪問權限XXXXXXXXXX
import PlaygroundSupport
import Foundation
let url = URL(string: "https://www.googleapis.com/storage/v1/b?project=<project id>")
let task = URLSession.shared.dataTask(with: url!) { data, response, error in
guard error == nil else {
print(error!)
return
}
guard let data = data else {
print("Data is empty")
return
}
let json = try! JSONSerialization.jsonObject(with: data, options: [])
print(json)
}
task.resume()
PlaygroundPage.current.needsIndefiniteExecution = true
不幸的是,這是什麼了:
{
error = {
code = 401;
errors = (
{
domain = global;
location = Authorization;
locationType = header;
message = "Anonymous users does not have storage.buckets.list access to project <project id>.";
reason = required;
}
);
message = "Anonymous users does not have storage.buckets.list access to project <project id>.";
};
}
谷歌雲文檔是非常混亂。在這種情況下,我不知道如何指定用戶。什麼是正確的方法?