好吧,我很确定我已通过身份验证,因为我遵循了所有教程并且代码几乎相同.
谁知道为什么会这样?为什么我可以插入文件,但无法查看它的Self link?
以下是用户允许应用程序进行离线访问后,在驱动器中创建文档的代码:
ScopES = [ 'https://www.GoogleAPIs.com/auth/drive','https://www.GoogleAPIs.com/auth/userinfo.email','https://www.GoogleAPIs.com/auth/userinfo.profile' ]class DriveAuthenticator def self.create_document(user,Title,description,parent_Title,user_array) clIEnt = DriveAuthenticator.initiate_clIEnt if user.Google_ID.present? if DriveAuthenticator.authenticate_clIEnt clIEnt,user parent_ID = get_parent_ID clIEnt,parent_Title file_data = insert_empty_file clIEnt,document_MIME_TYPE,parent_ID return file_data.selflink end end end private def self.initiate_clIEnt clIEnt = Google::apiclient.new(:application_name => 'stuff_app') credentials = Google::apiclient::ClIEntSecrets.load clIEnt.authorization.clIEnt_ID = credentials.clIEnt_ID clIEnt.authorization.clIEnt_secret = credentials.clIEnt_secret clIEnt.authorization.redirect_uri = credentials.redirect_uris.first clIEnt.authorization.scope = ScopES clIEnt end private def self.get_token_by_refresh_token(clIEnt,refresh_token) clIEnt.authorization.refresh_token = refresh_token clIEnt.authorization.grant_type = 'refresh_token' clIEnt.authorization.fetch_access_token! end private def self.insert_empty_file(clIEnt,mime_type,parent_ID) drive = clIEnt.discovered_API('drive','v2') file = create_file_schema drive,parent_ID result = clIEnt.execute( :API_method => drive.files.insert,:body_object => file) if result.status == 200 result.data else puts "An error occurred: #{result.data['error']['message']}" nil end end private def self.create_file_schema(drive,parent_ID) file = drive.files.insert.request_schema.new({ 'Title' => Title,'description' => description,'mimeType' => mime_type }) file.parents = [{'ID' => parent_ID}] file endend解决方法 您是否尝试在浏览器中打开该网址?文件自链接仍然需要访问授权,您应该向该URL发送授权的GET请求以检索其元数据.
Google Drive SDK文档中的参考指南显示了如何获取文件元数据和内容:
https://developers.google.com/drive/v2/reference/files/get
另请查看文档以获取有关如何从云端硬盘下载文件的指导,包括如何在浏览器中打开文件:
https://developers.google.com/drive/manage-downloads
总结以上是内存溢出为你收集整理的ruby – Google Drive API中的接收错误403 – 超出未经身份验证的使用的每日限制.继续使用需要注册全部内容,希望文章能够帮你解决ruby – Google Drive API中的接收错误403 – 超出未经身份验证的使用的每日限制.继续使用需要注册所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)