2017-02-21 134 views
3

我使用谷歌驅動API.When我嘗試使用來從驅動文件谷歌雲端硬盤API:沒有足夠的權限的iOS

let query = GTLQueryDrive.queryForFilesList() 
    let service = GTLServiceDrive() 
    query?.pageSize = 1 
    query?.fields = 「files」 
    service.executeQuery(
     query!, 
     delegate: self, 
     didFinish: #selector(self.displayResult(ticket:finishedWithObject:error:)) 
) 

我收到錯誤,如

「的操作不能」完成。(沒有足夠的權限)。

任何人都知道我需要設置在儀表板這允許嗎?

+0

你在谷歌API控制檯激活驅動API如果不是激活 –

+0

請檢查該https://developers.google .com/drive/v3/web/about-auth –

+0

您使用什麼範圍進行身份驗證? @Lalitkumar不是在開發者控制檯錯誤中未啓用。 – DaImTo

回答

0

如果用戶訪問非公開文件,請務必使用Google登錄。或者您對用戶相關的文件列表感興趣。

要這樣做,首先請求登錄。確保還要設置Google登錄的UIDelegate,以在正確的時間點提供登錄屏幕:GIDSignInUIDelegate。爲了呈現它,您可以撥打:

GIDSignIn.sharedInstance().signIn() 

如果用戶曾在已簽署的,您可以撥打:

if userSignedInBefore { 
    GIDSignIn.sharedInstance().signInSilently() 
} 

假設你有你的請求被稱爲在這樣一個特定的類(用於說明的想法):

class Requester { 
    static let service = GTLServiceDrive() 

    static func fetchData() { 
     let query = GTLQueryDrive.queryForFilesList() 
     query?.pageSize = 1 
     query?.fields = 「files」 
     service.executeQuery(query!, delegate: self, didFinish: #selector(self.displayResult(ticket:finishedWithObject:error:))) 
    } 
    ... 
} 

此外,你需要的GIDSignInDelegate一個代表這個人會照顧和存儲用戶的相關信息,當用戶登錄時:

// https://developers.google.com/identity/sign-in/ios/ 
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) { 
    // Perform any operations when the user disconnects from app here. 
    // ... 
    if (error == nil) { 
     // Perform any operations on signed in user here. 
     //   let userId = user.userID     // For client-side use only! 
     //   let idToken = user.authentication.idToken // Safe to send to the server 
     // .... 
     // Here you will receive an authorizer instance that implements the GTMFetcherAuthorizationProtocol protocol. 
     // This authorizer instance will be required by your GTLRDriveService services as authorizer reference. 
     // https://developers.google.com/identity/sign-in/ios/api/interface_g_i_d_authentication 
     var authorizer = user.authentication.fetcherAuthorizer() 

     // Here you can trigger any callback to now fetch the desired data 
     Requester.service.authorizer = authorizer 
     Requester.fetchData() 
    } else { 
     print("\(error.localizedDescription)") 
    } 
} 

欲瞭解更多信息或樣品實現看看谷歌的文檔: https://developers.google.com/drive/v3/web/quickstart/ios

相關問題