最近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请参阅上面的链接,这是我的问题,而这项任务的一切有我在做什么 –