Javascript Google picker api未进入onApiLoad函数
我想在我的应用程序中集成谷歌驱动器选择器api。但是google picker api的onload函数没有调用。下面是我的代码Javascript Google picker api未进入onApiLoad函数,javascript,google-api,google-drive-api,google-picker,Javascript,Google Api,Google Drive Api,Google Picker,我想在我的应用程序中集成谷歌驱动器选择器api。但是google picker api的onload函数没有调用。下面是我的代码 <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>GoogleDriveApi</title> <script type="text/j
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>GoogleDriveApi</title>
<script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad"></script>
</head>
<body>
<div>
</div>
<script type="text/javascript">
/**************************************************************** start of Google api code ************************************************************************************************/
// The API developer key obtained from the Google Developers Console.
var developerKey = 'AIzaSyAZjLxjshv3FpkLK6517tiZ2nYwt6rJZHk';
// The Client ID obtained from the Google Developers Console.
var clientId = '814476538527-pijtu7ck89ofep1j4tqr2j38ltruahtd.apps.googleusercontent.com';
// Scope to use to access user's photos.
var scope = ['https://www.googleapis.com/auth/drive'];
var pickerApiLoaded = false;
var oauthToken;
// Use the API Loader script to load google.picker and gapi.auth.
function onApiLoad() {
console.log("load function calledd");
gapi.load('auth', { 'callback': onAuthApiLoad });
gapi.load('picker', { 'callback': onPickerApiLoad });
}
function onAuthApiLoad() {
console.log("auth api success");
window.gapi.auth.authorize(
{
'client_id': clientId,
'scope': scope,
'immediate': false
},
handleAuthResult);
}
function onPickerApiLoad() {
console.log("picker load");
pickerApiLoaded = true;
createPicker();
}
function handleAuthResult(authResult) {
console.log("authressult");
console.log(authResult);
if (authResult && !authResult.error) {
oauthToken = authResult.access_token;
createPicker();
}
}
// Create and render a Picker object for picking user Photos.
function createPicker() {
console.log("create picker");
if (pickerApiLoaded && oauthToken) {
var picker = new google.picker.PickerBuilder().
addView(google.picker.DocsUploadView()).
setOAuthToken(oauthToken).
setDeveloperKey(developerKey).
setCallback(pickerCallback).
build();
picker.setVisible(true);
}
}
// A simple callback implementation.
function pickerCallback(data) {
var url = 'nothing';
if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
var doc = data[google.picker.Response.DOCUMENTS][0];
url = doc[google.picker.Document.URL];
}
var message = 'You picked: ' + url;
document.getElementById('result').innerHTML = message;
}
/**************************************************************** end of Google api code ************************************************************************************************/
</script>
控制器代码
public ActionResult GoogleApi(){
retunr View("GoogleApi");
}
正在加载GoogleApi.cshmtl页面,但它没有调用onApiLoad函数。我已将Google PickerAPI设置为On。任何人都可以知道这其中的错误。使用脚本: script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad"> 身体而不是脑袋对我很有用。但我不知道确切的原因。希望你现在已经明白了,因为这篇文章已经发布6个月了。如果你现在知道这些脚本是如何执行的,请让我知道!我指的是执行的顺序 script type="text/javascript" src="https://apis.google.com/js/api.js?onload=onApiLoad">