2017-07-24 264 views
0

因此,基本上這可以讓我打開Goog​​le雲端硬盤並要求登錄,然後在驅動器中加載一些文件。我想知道如何列出和修改權限。任何幫助,將不勝感激!感謝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) 
} 

}

回答

0

嗯,我希望有關permission.list本文檔可幫助您獲得您需要的清單,並permission.update修改權限。

權限

對於此資源的方法列表,請參閱本頁面的結尾。

資源表示

對文件的權限。權限授予用戶,組,域或全球對文件或文件夾層次結構的訪問權限。

以下是有關Permissions的參考文獻。

相關問題