我按照此文档create-react-app
创建了一个简单的应用它很棒! 然后我想在js中使用google的api,因为你可以阅读here
导入“选项1”脚本。我已经在一个html文件中对它进行了测试,但它确实有效。所以,我想在我的反应应用程序中使用该js脚本(例如调用'start()'函数onclick,我知道如何做到这一点)。我试过了:import {start} from './apiCall';
var gapi = require('gapi');
其中apiCall是我的js:
export function start() {
// 2. Initialize the JavaScript client library.
gapi.client.init({
'apiKey': 'YOUR_API_KEY',
// Your API key will be automatically added to the Discovery Document URLs.
'discoveryDocs': ['https://people.googleapis.com/$discovery/rest'],
// clientId and scope are optional if auth is not required.
'clientId': 'YOUR_WEB_CLIENT_ID.apps.googleusercontent.com',
'scope': 'profile',
}).then(function() {
// 3. Initialize and make the API request.
return gapi.client.people.people.get({
resourceName: 'people/me'
});
}).then(function(response) {
console.log(response.result);
}, function(reason) {
console.log('Error: ' + reason.result.error.message);
});
};
// 1. Load the JavaScript client library.
gapi.load('client', start);
此时我收到很多Coffee-Script错误:
Error in ./~/coffee-script/lib/coffee-script/coffee-script.js
Module not found: 'module' in C:\Users\Lavoro\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script
Error in ./~/coffee-script/lib/coffee-script/register.js
Module not found: 'child_process' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script
Error in ./~/coffee-script/lib/coffee-script/register.js
Module not found: 'module' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script
Module not found: 'child_process' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script
Error in ./~/coffee-script/lib/coffee-script/grammar.js
Module not found: 'jison' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script
Error in ./~/coffee-script/lib/coffee-script/repl.js
Module not found: 'repl' in C:\Users\Work\Desktop\calendar_test_vm\vm_calendar\node_modules\coffee-script\lib\coffee-script
如何正确导入外部函数(在本例中为GAPI函数)?