最近Google OAuth策略發生變化後,針對此問題有一個解決方法。
集成Google Sign並啓用Google Drive API後,我可以使用Google Drive API來獲取所有驅動器數據。我們只需設置GTLServiceDrive的授權人,這是在Google登錄後獲得的。
service.authorizer = user.authentication.fetcherAuthorizer()
下面是谷歌GIDSignIn的代碼片斷,然後獲取日曆事件。
import GoogleAPIClient
import GTMOAuth2
import UIKit
import GoogleSignIn
class ViewController: UIViewController, GIDSignInUIDelegate, GIDSignInDelegate {
private let kApiKey = "AIzaXXXXXXXXXXXXXXXXXXXXXXX"
// If modifying these scopes, delete your previously saved credentials by
// resetting the iOS simulator or uninstall the app.
private let scopes = [kGTLAuthScopeDriveMetadataReadonly]
private let service = GTLServiceDrive()
override func viewDidLoad() {
super.viewDidLoad()
service.apiKey = kApiKey
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().scopes = scopes
GIDSignIn.sharedInstance().signIn()
GIDSignIn.sharedInstance().delegate = self
}
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if user != nil {
print("\(user)")
service.authorizer = user.authentication.fetcherAuthorizer()
loadDriveFiles()
}
}
// Construct a query and get a list of upcoming events from the user calendar
func loadDriveFiles() {
//Googly Drive fetch Query
}
}
顯示你的代碼或HTTP reuqest什麼的? – Liam
http://stackoverflow.com/questions/40233330/cannot-download-file-from-google-drive-in-ios?noredirect=1#comment68213104_40233330 –
@Liam請參閱上面的鏈接,這是我的問題,而這項任務的一切有我在做什麼 –