Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
为什么Javascript Google drive API返回';假';作为回应?_Javascript_Google Drive Api_Google Client_Google Api Js Client - Fatal编程技术网

为什么Javascript Google drive API返回';假';作为回应?

为什么Javascript Google drive API返回';假';作为回应?,javascript,google-drive-api,google-client,google-api-js-client,Javascript,Google Drive Api,Google Client,Google Api Js Client,我正在使用GoogleDriveAPIv3检索一个文件。我可以上传文件和列出文件,但files.get调用返回“false”。文档非常稀疏() 如果我删除了“alt:'media'”参数,那么我将按照文档中的描述返回元数据。我还尝试使用: gapi.client.request ( { 'path': '/drive/v3/files/'+fileId, 'method': 'GET', 'params': {'fileId': fileId, 'alt': '

我正在使用GoogleDriveAPIv3检索一个文件。我可以上传文件和列出文件,但files.get调用返回“false”。文档非常稀疏()

如果我删除了“alt:'media'”参数,那么我将按照文档中的描述返回元数据。我还尝试使用:

gapi.client.request
    ( { 
    'path': '/drive/v3/files/'+fileId,
    'method': 'GET',
    'params': {'fileId': fileId, 'alt': 'media'},
    'headers': {'Authorization': 'Bearer ' + gapi.auth.getToken().access_token }
    }).execute(function(file) { 
         // file = false 
      }); 
我能找到的唯一希望就藏在Google客户端REST API文档中,文档中说如果不能解析JSON,那么响应是“错误的”


文件的类型似乎没有什么区别。。。到目前为止,我已经尝试了.html和.txt。

我相信这就是您要寻找的链接:)

下载文件要求用户至少具有读取权限。此外,您的应用程序必须获得允许读取文件内容的范围的授权。例如,使用drive.readonly.metadata作用域的应用程序将无权下载文件内容。具有编辑权限的用户可以通过将viewersCanCopyContent字段设置为true来限制只读用户的下载


您需要使用回调的第二个参数-它应该包含原始响应

request.execute(function(jsonResp, rawResp) {
    console.log('rawResp: ', rawResp);
    var respObject = JSON.parse(rawResp); // rawResp is encoded JSON string with header, body, etc.
    var respBody = respObject.gapiRequest.data.body; // in my case here it outputs the text of my txt file
});
当请求成功或失败时执行的回调函数。jsonResp包含解析为JSON的响应。如果响应不是JSON,则此字段将为false。rawrep是HTTP响应。它是JSON,可以解析为包含body、header、status和statusText字段的对象

src:


另外,关于“不可解析JSON”的文档很不错!它帮助我解决了这个问题

在请求对象上调用execute时,我得到一个错误的响应。但是当你叫“then”的时候,它就起作用了

request.then(function(resp) {
   console.log(resp);
   console.log(resp.body); // The file content
});

这并不能回答问题。我有同样的问题,已经阅读(并遵循)参考链接。我得到的响应为false,要求完全访问驱动器并在请求中使用{fileId:id,alt:'media'})。Rawrep是[{“id”:“gapiRpc”,“result”:false}]。。。还有什么想法吗?@user5886944没有
正文
,没有
状态
,没有更多的
rawrep
?很奇怪。。。尝试获取其他格式的文件,甚至请求其他文件。
request.then(function(resp) {
   console.log(resp);
   console.log(resp.body); // The file content
});