0
因此,基本上這可以讓我打開Google雲端硬盤並要求登錄,然後在驅動器中加載一些文件。我想知道如何列出和修改權限。任何幫助,將不勝感激!感謝Google雲端硬盤權限IOS
import GoogleAPIClientForREST
import GoogleSignIn
import UIKit
class ViewController: UIViewController, GIDSignInDelegate, GIDSignInUIDelegate {
// If modifying these scopes, delete your previously saved credentials by
// resetting the iOS simulator or uninstall the app.
private let scopes = [kGTLRAuthScopeDriveReadonly]
private let service = GTLRDriveService()
let signInButton = GIDSignInButton()
let output = UITextView()
override func viewDidLoad() {
super.viewDidLoad()
// Configure Google Sign-in.
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().scopes = scopes
GIDSignIn.sharedInstance().signInSilently()
// Add the sign-in button.
view.addSubview(signInButton)
// Add a UITextView to display output.
output.frame = view.bounds
output.isEditable = false
output.contentInset = UIEdgeInsets(top: 20, left: 0, bottom: 20, right: 0)
output.autoresizingMask = [.flexibleHeight, .flexibleWidth]
output.isHidden = true
view.addSubview(output);
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!,
withError error: Error!) {
if let error = error {
showAlert(title: "Authentication Error", message: error.localizedDescription)
self.service.authorizer = nil
} else {
self.signInButton.isHidden = true
self.output.isHidden = false
self.service.authorizer = user.authentication.fetcherAuthorizer()
listFiles()
}
}
// List up to 10 files in Drive
func listFiles() {
let query = GTLRDriveQuery_FilesList.query()
query.pageSize = 3
service.executeQuery(query,
delegate: self,
didFinish: #selector(displayResultWithTicket(ticket:finishedWithObject:error:))
)
}
func listPermissions() {
let query = GTLRDriveQuery_PermissionsList.query(withFileId: "1Tb9PY4fNl2XRPe5k-ZkqTZG4TLi-s_sC-Kvo82lRo9g")
query.pageSize = 3
service.executeQuery(query,
delegate: self,
didFinish: #selector(displayPermissionsWithTicket(ticket:finishedWithObject:error:))
)
}
//1Tb9PY4fNl2XRPe5k-ZkqTZG4TLi-s_sC-Kvo82lRo9g
// Process the response and display output
func displayResultWithTicket(ticket: GTLRServiceTicket,
finishedWithObject result : GTLRDrive_FileList,
error : NSError?) {
if let error = error {
showAlert(title: "Error", message: error.localizedDescription)
return
}
var text = "";
if let files = result.files, !files.isEmpty {
text += "Files:\n\n"
for file in files {
text += "\(file.name!)(\(file.identifier!))\n\n" //(\(file.identifier!))
}
} else {
text += "No files found."
}
output.text = text
}
// Process the response and display output
func displayPermissionsWithTicket(ticket: GTLRServiceTicket,
finishedWithObject result : GTLRDriveQuery_PermissionsList,
error : NSError?) {
if let error = error {
showAlert(title: "Error", message: error.localizedDescription)
return
}
var text = "";
if let files = result.files, !files.isEmpty {
text += "Files:\n\n"
for file in files {
text += "\(file.name!)(\(file.identifier!))\n\n" //(\(file.identifier!))
}
} else {
text += "No files found."
}
output.text = text
}
// Helper for showing an alert
func showAlert(title : String, message: String) {
let alert = UIAlertController(
title: title,
message: message,
preferredStyle: UIAlertControllerStyle.alert
)
let ok = UIAlertAction(
title: "OK",
style: UIAlertActionStyle.default,
handler: nil
)
alert.addAction(ok)
present(alert, animated: true, completion: nil)
}
}