I have been trying to find out what is incorrect with my Google Drive Picker integration but haven't been able to.
Once the picker opens, I'm shown a "Sign In" screen, which then opens the OAuth flow for the first time. After completing that it repeats the Sign In screen again. On clicking it again this time, it show the error - "The feature you requested is currently unavailable. Please try again later."
I have tried searching for various answers but none have worked. I have tried adding OAuth flow before the picker initialisation but it still does not solve the problem. Any help will be appreciated.
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>
);
}
}