podio API JS 浏览器身份验证和 API 调用
podio API JS browser authentication and API calls
我在 API 方面还是个新手,一直在阅读 JAVASCRIPT 客户端的文档 here,但我无法使事情正常进行,即使是在身份验证部分。我已经从 PODIO 本身获得了客户端 ID 和 ClientSecret。
基本上,我想使用客户端(仅限浏览器)以 JSON 格式获取工作区中的所有跑道数据。
我已经下载了库 here 并在我的本地主机上创建了一个 HTML 文件,并使用以下代码 link podio-js。收到此错误 "podio-js.js:1 Uncaught ReferenceError: require is not defined at podio-js.js:1"。我需要安装类似加载程序的东西才能使它工作吗?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="lib/podio-js.js"></script>
<script type="text/javascript">
var podio = new PodioJS({
authType: 'server',
clientId: 'foo',
clientSecret: 'foo'
});
var redirectURL = 'http://localhost/PODIO-JS/podio-js-master/PODIO_CLIENT.html';
// Your request handler (for example in ExpressJS)
var action = function(request, response) {
var authCode = request.query.code;
var errorCode = request.query.error;
podio.isAuthenticated().then(function() {
// Ready to make API calls...
}).catch(function(err) {
if (typeof authCode !== 'undefined') {
podio.getAccessToken(authCode, redirectURL, function(err, response) {
// make API calls here
console.log (responsedata);
});
} else if (typeof errorCode !== 'undefined') {
// a problem occured
console.log(request.query.error_description);
} else {
// start authentication via link or redirect
console.log(podio.getAuthorizationURL(redirectURL));
}
});
</script>
</head>
<body>
</body>
</html>
如果您在 AMD 环境中工作,则只能使用语法 PodioJS = require('podio-js')
,通常使用 requirejs
。
您使用的是一个很好的 HTML 页面,这意味着您必须遵循此处的浏览器使用部分的第二部分:https://github.com/podio/podio-js#browser
从 podio-js
文件夹中:
npm install -g browserify
npm run bundle
然后在 HTML 页面中使用标签包含 dist/podio-js.js
。
注意:一旦您捆绑了源代码,您就可以将编译后的文件复制粘贴到任何您想要的地方。
我在 API 方面还是个新手,一直在阅读 JAVASCRIPT 客户端的文档 here,但我无法使事情正常进行,即使是在身份验证部分。我已经从 PODIO 本身获得了客户端 ID 和 ClientSecret。
基本上,我想使用客户端(仅限浏览器)以 JSON 格式获取工作区中的所有跑道数据。
我已经下载了库 here 并在我的本地主机上创建了一个 HTML 文件,并使用以下代码 link podio-js。收到此错误 "podio-js.js:1 Uncaught ReferenceError: require is not defined at podio-js.js:1"。我需要安装类似加载程序的东西才能使它工作吗?
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script type="text/javascript" src="lib/podio-js.js"></script>
<script type="text/javascript">
var podio = new PodioJS({
authType: 'server',
clientId: 'foo',
clientSecret: 'foo'
});
var redirectURL = 'http://localhost/PODIO-JS/podio-js-master/PODIO_CLIENT.html';
// Your request handler (for example in ExpressJS)
var action = function(request, response) {
var authCode = request.query.code;
var errorCode = request.query.error;
podio.isAuthenticated().then(function() {
// Ready to make API calls...
}).catch(function(err) {
if (typeof authCode !== 'undefined') {
podio.getAccessToken(authCode, redirectURL, function(err, response) {
// make API calls here
console.log (responsedata);
});
} else if (typeof errorCode !== 'undefined') {
// a problem occured
console.log(request.query.error_description);
} else {
// start authentication via link or redirect
console.log(podio.getAuthorizationURL(redirectURL));
}
});
</script>
</head>
<body>
</body>
</html>
如果您在 AMD 环境中工作,则只能使用语法 PodioJS = require('podio-js')
,通常使用 requirejs
。
您使用的是一个很好的 HTML 页面,这意味着您必须遵循此处的浏览器使用部分的第二部分:https://github.com/podio/podio-js#browser
从 podio-js
文件夹中:
npm install -g browserify
npm run bundle
然后在 HTML 页面中使用标签包含 dist/podio-js.js
。
注意:一旦您捆绑了源代码,您就可以将编译后的文件复制粘贴到任何您想要的地方。