我一直在尝试找出我的 Google Drive Picker 集成有什么问题,但一直没能找到。
选择器打开后,我会看到一个“登录”屏幕,然后首次打开 OAuth 流程。完成后,它会再次重复登录屏幕。这次再次点击它会显示错误 - “您请求的功能当前不可用。请稍后再试。”
我曾尝试寻找各种答案,但都没有奏效。我曾尝试在选择器初始化之前添加 OAuth 流,但它仍然不能解决问题。任何帮助将不胜感激。
import { h, Component } from 'preact';
import googleClientAPI from 'google-client-api';
import styles from 'stylesheets/components/commons/drive';
import config from '../../config';
export default class DriveFilePicker extends Component {
constructor(props) {
super(props);
this.setState({
loaded: false,
});
}
componentWillMount() {
googleClientAPI().then(gapi => {
gapi.load('picker', this.buildPicker);
});
}
handleAuthResult = (authResult) => {
if (authResult && !authResult.error) {
oauthToken = authResult.access_token;
this.buildPicker(oauthToken);
}
}
buildPicker = (accessToken) => {
accessToken = accessToken || this.props.accessToken;
if (typeof google !== 'undefined' && typeof accessToken !== 'undefined') {
const docsView = new google.picker.DocsView()
.setIncludeFolders(true)
.setMimeTypes('application/vnd.google-apps.folder')
.setSelectFolderEnabled(true);
this.picker = new google.picker.PickerBuilder()
.enableFeature(google.picker.Feature.MULTISELECT_ENABLED)
.addView(docsView)
.setOAuthToken(accessToken)
.setDeveloperKey(config.gapi.developerKey)
.setCallback(this.onPicked)
.build();
this.setState({
loaded: true,
});
}
}
componentWillReceiveProps({ accessToken: nextAccessToken }) {
if (this.props.accessToken !== nextAccessToken) {
this.setState({
loaded: false,
});
this.buildPicker(nextAccessToken);
}
}
onPicked = ({ action, docs }) => {
if (action === 'picked') {
this.props.onAddFolder(docs);
}
}
onOpen() {
this.state.loaded && this.picker.setVisible(true);
}
render() {
const { loaded } = this.state;
return (
<div className={`${!loaded ? styles.disabled : ''} ${styles.drive}`}>
<div className={styles.label}>Sync folders</div>
<div className={`${!loaded ? styles.disabled : ''} ${styles.folders}`}>
<Tag hideRemove={true} onClick={::this.onOpen}>+Add folder</Tag>
</div>
</div>
);
}
}