无法从ios将照片上传到googleDrive

时间:2016-04-23 11:26:56

标签: ios swift google-drive-api

我按照https://developers.google.com/drive/ios/quickstart的教程进行操作 我注册我的应用程序,获得密钥并将其放入应用程序中,在此获取一些令牌:       func viewController(vc:UIViewController,                       finishedWithAuth authResult:GTMOAuth2Authentication,error:NSError?){

if let error = error {
  service.authorizer = nil
  showAlert("Authentication Error", message: error.localizedDescription)
  return
}
service.authorizer = authResult

没关系。但当我试图上传照片到谷歌光盘 - 我收到此错误: {"错误":{"代码":403,"消息":"权限不足""数据": [{"结构域":"全球""理由":" insufficientPermissions""消息":&#34 ;权限不足"}]}," id":" gtl_1"} 2016-04-23 14:21:06.329 PROJECT_NAME [560:210039]过早失败:上传状态:"最终"位置:(空)

这是代码。有人能告诉我我做错了什么吗?

func uploadPhoto(image: UIImage) {
  let name = "Photo"
  let content = image
  let mineType = "image/jpeg"

  let metadata = GTLDriveFile()
  metadata.name = name

  guard let data = UIImagePNGRepresentation(content) else {
    return
  }
  let uploadParameters = GTLUploadParameters(data: data, MIMEType: mineType)
  let query = GTLQueryDrive.queryForFilesCreateWithObject(metadata,    uploadParameters: uploadParameters) as GTLQueryDrive
  service.executeQuery(query) { (ticket, updatedFile, error) in
    print(ticket)
    if error != nil {
      print(error)
    }
  }
}  

0 个答案:

没有答案