- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直试图找出我的 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>
);
}
}
最佳答案
终于得到这一系列的函数加载api
platform
和 client
, 我有 <script src/>
在 index.html
也是,但我认为当 appendChild
时不需要这样做script
安装后。加载顺序api
至 platform
至 client:auth2
,然后构建 picker
成功后 authResult
来自 authorize
似乎很重要。我无法获得 sign-in2
+ init
工作所以我使用 authorize
var SCOPES = "https://www.googleapis.com/auth/drive.file"
...
componentDidMount = () => {
this.loadGoogleAPI()
}
加载谷歌脚本
loadGoogleApi() {
const script = document.createElement("script");
script.src = "https://apis.google.com/js/api.js";
script.onload = () => {
console.log("google api loaded");
this.loadGapi();
};
document.body.appendChild(script);
}
loadGapi = () => {
const script = document.createElement("script");
script.src = "https://apis.google.com/js/platform.js";
script.onload = () => {
console.log("google api platform loaded");
this.loadGapiClient();
};
document.body.appendChild(script);
};
loadGapiClient = () => {
const script = document.createElement("script");
script.src = "https://apis.google.com/js/client.js";
script.onload = () => {
console.log("google api client loaded");
/*this.gapi.client.load("youtube", "v3", () =>
console.log("loaded youtube")
);*/
this.gapi = window.gapi;
this.gapi.load("client:auth2", () => {
/*this.gapi.load("signin2", () => {
console.log("render a sign in button");
// using this method will show Signed In if the user is already signed in
});*/
console.log("auth2 loaded");
});
};
document.body.appendChild(script);
};
单击谷歌品牌登录按钮
loadGapiApi = () => {
//var DIALOG_DIMENSIONS = { width: "90%", height: "90%" };
this.gapi = window.gapi;
console.log("authooo");
this.gapi.auth2.authorize(
//getAuthInstance().signIn(
//init(
//authorize(
{
api_key: API_KEY,
client_id: CLIENT_ID,
scope: SCOPES,
prompt: "none"
//prompt: "select_account"
},
(authResult) => {
if (authResult) {
this.gapi.client.load("drive", "v3", () =>
console.log("loaded drive")
);
this.gapi.load("picker", () => {
console.log("drive picker loaded");
this.googlepicker = window.google;
var view1 = new this.googlepicker.picker.DocsView(
this.googlepicker.picker.ViewId.IMAGE
).setSelectFolderEnabled(true);
var view = new this.googlepicker.picker.DocsView(
this.googlepicker.picker.ViewId.DOCS
).setSelectFolderEnabled(true);
var uploadView = new this.googlepicker.picker.DocsUploadView();
view.setMode(this.googlepicker.picker.DocsViewMode.LIST);
view.setQuery(window.dataFeedName);
this.picker = new this.googlepicker.picker.PickerBuilder()
.setAppId(CLIENT_ID)
.setOAuthToken(authResult.access_token)
.addView(view)
.addView(uploadView)
//.enableFeature(google.picker.Feature.SIMPLE_UPLOAD_ENABLED)
//.enableFeature(google.picker.Feature.SUPPORT_TEAM_DRIVES)
.enableFeature(
this.googlepicker.picker.Feature.MULTISELECT_ENABLED
) //optional
.setOrigin("https://thumbprint.us")
.setCallback(this.pickerCallback)
.build();
window.picker = this.picker;
});
this.gapi.load("drive-share", () => {
console.log("share dialog loaded");
this.s = window.s;
this.s = new window.gapi.drive.share.ShareClient();
this.s.setOAuthToken(authResult.access_token);
});
this.setState({
authResult,
accessToken: authResult.access_token,
authorizedScopes: true,
signedIn: true
});
//const auth2 = this.gapi.auth2.getAuthInstance();
//this.auth2.signIn();
}
}
);
};
共享驱动器和注销
logout = () => {
window.location.href =
"https://www.google.com/accounts/Logout?continue=https://appengine.google.com/_ah/logout?continue=https://thumbprint.us";
};
signOut = () => {
console.log("trying to sign out");
if (this.gapi) {
//console.log(auth2);
this.auth2 = window.auth2;
this.auth2
.signOut()
.then(() => {
//if (auth2 !== null) {
console.log("outted successfully");
this.auth2.disconnect();
})
.catch((err) => console.log(err.message));
this.auth2.disconnect();
//this.logout();
}
};
switchAccount = () => {
console.log("trying to sign out");
this.gapi = window.gapi;
this.gapi.auth2
.getAuthInstance()
.signIn({
api_key: API_KEY,
client_id: CLIENT_ID,
scope: SCOPES,
prompt: "select_account"
})
.then(() => {
//if (auth2 !== null) {
console.log("outted successfully");
this.auth2.disconnect();
})
.catch((err) => console.log(err.message));
};
pickerCallback = (data) => {
if (data.action === window.google.picker.Action.PICKED) {
var fileId = data.docs[0].id;
//console.log(fileId);
//console.log(window.gapi);
//console.log(data.docs[0].name);
this.s.setItemIds([fileId]);
if (this.state.filesPreparedToSend !== data.docs) {
//console.log(data.docs);
this.setState({ filesPreparedToSend: data.docs });
}
}
};
关于javascript - 打开 Google Drive Picker 时出错 - 您请求的功能当前不可用。请稍后再试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56367154/
我正在尝试使用 Drive SDK 将文件上传到 Google Drive . 我想知道是否有 API 方法来检查用户的驱动器是否有足够的容量来保存文件。如果是,请指出我应该搜索的位置,如果不是,最好
我想在我正在开发的新 android 应用程序(又名 drive.appdata 范围)中使用特殊应用程序数据文件夹中的文件。 谷歌的你们在与 Google Play Services 4.2 捆绑的
列出Google云端硬盘文件的JavaScript示例使用gapi.client.drive.files.list()。 尝试使用此方法时,出现错误“无法读取未定义的属性'files'”。 该问题和解
我正在尝试使用 Google Cloud REST API 获取特定文件夹大小。 我已经尝试过使用 REST API 的“ about ”方法,但在这种方法中,我获得了整个云存储的已用字节总数和可用空
我只是想了解在 G Suite 上使用 Team Drive 获取团队存储库与仅使用 Google Drive 上的共享文件夹相比的优势。通过搜索不同的来源并进行测试,到目前为止我发现了以下结果。 坦
我正在尝试使用 Google Drive API (v3) 更新文档 在 Google 云端硬盘中。 我已阅读此迁移指南: Google Drive API v3 Migration 并对其进行编码以
我曾尝试将我的 Web 应用程序集成到 Google 云端硬盘用户界面(以打开文件),但没有取得多大成功。我无法使用 OAuth 范围 https://www.googleapis.com/auth/
使用Google Drive API时 我使用 com.google.api.services.drive.Drive.files() 来迭代一些文件。 我注意到所有目录对象都没有权限? 当我使用 F
Google Drive API 和 Google Spreadsheet API (v 3.0) 都支持获取与以下 URL 对应的 [KEY] 的方法: https://docs.google.co
我正在尝试将本地 CSV 文件上传到 Google Drive 并在那里像 Google 电子表格一样显示它。但是,当我转到 Google Drive 并单击指向我的文件的链接时,我只能下载它,而不能
我正在尝试使用 ArrayBuffer 的内容在 Google Drive 上创建一个文件。我正在使用 Javascript 和 Drive API 的第 3 版。 我设法使用 this code s
我可以使用 google drive android api 将文本文件上传到 google drive 中的文件夹。 Sample code 但是我想上传一张图片到谷歌驱动器。这可能吗? 创建文本文
我想知道以下是否可行,因为我似乎无法在网上找到任何具体的方法: 当 Google Takeaway 服务将新的 takeout-xxx.zip 文件上传到我的 Google Drive Takeawa
是否可以对 Google Drive 上的文件执行“追加”操作? 假设我想使用 Google Drive 保存日志条目“as-they-come-in”,是否有某种“仅附加”操作可用? 最佳答案 如果
看着 Google Drive scopes .我明白: https://www.googleapis.com/auth/drive.install - 用于让用户批准安装应用程序的特殊范围 如果我希
我有一个带有两个父文件夹( FILE-1 和 FOLDER-1 )的文档( FOLDER-2 )。 如果我删除 FOLDER-1 , FILE-1也被删除。然而,我预计只有FOLDER-1将被删除,并
我正在测试Google Drive API。测试脚本执行HTTP GET来访问Files-> List API,但是我总是以某种方式在项目中得到一个空列表。我的Google驱动器中有数百个文件,因此结
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我将我的应用程序的文件托管在 Google Drive 上,它会在首次启动后立即下载它们。一切都很好,但在我发布新的应用程序版本后,下载数量不断增加,文件由于某些原因变得不可用。虽然我没有改变任何东西
我是一名优秀的程序员,十分优秀!