首先,经过一些研究,我发现很多人都遇到过这个问题,但我没有找到任何具体的解决方案。说到这个问题,
客观的:
我想将谷歌驱动器与我的应用程序集成,以便用户可以从我的应用程序将文件上传到他们的驱动器。因此,用户首先必须将其驱动器与应用程序集成,然后使用谷歌选择器上传/导入文件。集成 Google 驱动器后,用户不应再次看到身份验证屏幕,而是直接单击按钮即可打开 Google 选择器.
执行:
在集成时,我在服务器端使用 OAuth2 并存储以下客户端凭据
{
access_token: '',
refresh_token: '',
scope: 'https://www.googleapis.com/auth/drive.file https://www.googleapis.com/auth/userinfo.email openid',
token_type: 'Bearer',
expiry_date: 1578194339897
}
现在在客户端,我正在获取相同的访问令牌并用于加载选择器
createPicker() {
const { accessToken } = this.props.userInfo;
const uploadView = new google.picker.DocsUploadView();
var picker = new google.picker.PickerBuilder().
addViewGroup(
new google.picker.ViewGroup(google.picker.ViewId.DOCS).
addView(google.picker.ViewId.DOCUMENTS).
addView(google.picker.ViewId.PRESENTATIONS)
).
addView(uploadView).
setOAuthToken(accessToken). //access token fetched from server
setDeveloperKey(developerKey).
setCallback(this.pickerCallback).
build();
picker.setVisible(true);
}
Expected behaviour: Google picker should open on click of a button.
我尝试使用登录选项来获取当前用户,但无法获取当前用户。
除此之外,我还尝试使用gapi进行客户端授权,但每次我尝试加载选择器时它也会要求身份验证屏幕
任何帮助表示赞赏。提前致谢。