javascript - podio API JS浏览器认证和API调用

标签 javascript api podio

我对 API 很陌生,一直在阅读文档 here对于 JAVASCRIPT 客户端,但我无法使事情正常工作,即使在身份验证部分也是如此。我已经从 PODIO 本身获得了客户端 ID 和 ClientSecret。

基本上,我想使用客户端(仅限浏览器)以 JSON 格式获取工作区中的所有跑道数据。

我已经下载了该库here并在我的本地主机上创建了一个 HTML 文件,并使用以下代码链接 podio-js 。收到此错误“podio-js.js:1 Uncaught ReferenceError: require 未在 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

注意:捆绑源代码后,您可以将编译后的文件复制粘贴到任何您想要的位置。

关于javascript - podio API JS浏览器认证和API调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41394652/

相关文章:

javascript - 如何正确通知我的 observablearray 刷新它在 knockoutjs 中的 View ?

javascript - 创建 JavaScript 函数的其他方法

javascript - 用于检索 Podio 项目的 http 请求的完整 URI

Podio WebHooks RequestBin 测试

javascript - 无法从 html 文本框获取实时字数

api - Cosmos DB 的分区键

javascript - 如何使用 PHP 或 JavaScript 请求 Steam API 超过 10000 次?

php - 在 Etsy 上创建新列表

python - 如何编辑已安装的 Python 3 API 中的错误?

javascript - 在 JavaScript 中获取方向上的最近点