【发布时间】:2020-04-22 12:58:25
【问题描述】:
我在我的项目中使用了 react-native-google-drive-api-wrapper,我可以成功登录,但仍然无法在 google drive 上创建或上传任何内容。我错过了什么?
signIn = async () => {
try {
await GoogleSignin.hasPlayServices();
const userInfo = await GoogleSignin.signIn();
const token= (await GoogleSignin.getTokens()).accessToken;
// console.log();
this.setState({ userInfo : userInfo, accToken: token, email : userInfo.user.email});
// alert('info is '+ userInfo.user.familyName);
GDrive.setAccessToken(this.state.accToken);
GDrive.init();
// alert("gdrive done")
if(GDrive.isInitialized()){
alert("Google Drive is Initialized Now!!")
const contents = "My text file contents";
GDrive.files.createFileMultipart(
contents,
"text/plain", {
parents: ["root"],
name: "text2.txt"
},
false);
// this.createAFile();
}
} catch (error) {
alert('error is '+ error);}
我错过了什么?这是访问accessToken的正确方法吗,还是有其他错误,请帮忙。
在 console.log(JSON.stringify(response)) 之后我得到
LOG {"type":"default","status":403,"ok":false,"headers":{"map":
{"content-
type"
:"application/json; charset=UTF-8","vary":"Origin, X-
Origin","date":"Wed, 22 Apr
2020 14:33:41 GMT","www-authenticate":"Bearer
realm=\"https://accounts.google.c
om/\", error=insufficient_scope,
scope=\"https://www.googleapis.com/auth/drive\"
","server":"UploadServer","alt-svc":"quic=\":443\"; ma=2592000;
v=\"46,43\",h3-Q
050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-
Q048=\":443\"; ma=25920
00,h3-Q046=\":443\"; ma=2592000,h3-Q043=\":443\"; ma=2592000,h3-
T050=\":443\"; m
a=2592000","content-length":"306","x-guploader-
uploadid":"AAANsUm9Zk5l-FX8wKLBku
ZUaYyxfMr403jozVOIj8Q7zt5AGORvLIEw0hUjNSfUsaiMt06LBTkJDa9SwzB98QCjkR8"}},"url" :"
https://www.googleapis.com/upload/drive/v3/files?
uploadType=multipart","_bodyIni
t":{"_data":{"size":306,"offset":0,"blobId":"29e54a64-a7cd-4b5b-8c2f-
6fe63d9391f
b","__collector":{}}},"_bodyBlob":{"_data"
{"size":306,"offset":0,"blobId":"29e5
4a64-a7cd-4b5b-8c2f-6fe63d9391fb","__collector":{}}}}
【问题讨论】:
-
你能分享你收到的错误吗?
-
请分享您使用的 API 包装器的链接。 gspread 对吗?
-
npmjs.com/package/react-native-google-drive-api-wrapper 这是该 api 包装器的链接
-
你收到的错误是什么?
-
这是 403 错误,当我 JSON.stringify(response) 时,这就是我得到的。 {"type":"default","status":403,"ok":false,"headers":{"map":{"content-type":"application/json; charset=UTF-8","不同":"Origin, X-Origin","date":"2020 年 4 月 22 日星期三 14:33:41 GMT","www-authenticate":"Bearer realm=\"accounts.google.com/\", 错误=insufficient_scope, scope=\"googleapis.com/auth/drive\" ","server":"UploadServer","alt-svc":"quic=\":443\"; ma=2592000; v=\"46,43\ ",h3-Q 050=\":443\"; ma=2592000,h3-Q049=\":443\"; ma=2592000,h3-Q048=\":443\"; ma=25920 }跨度>
标签: react-native google-drive-api access-token