2016-12-30 83 views
1

我是API上的新手,已經閱讀了JAVASCRIPT客戶端的文檔here,但我無法使事情工作,即使在身份驗證部分。我已經有PODIO本身的客戶端ID和ClientSecret。podio API JS瀏覽器身份驗證和API調用

基本上,我想使用客戶端(僅瀏覽器)以JSON格式獲取工作區中的所有podio數據。

我已經下載了庫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> 

回答

2

,如果你在AMD環境中工作,通常使用requirejs您只能使用語法PodioJS = require('podio-js')

您使用的好醇」的HTML頁面,而不是,這意味着你必須遵循在這裏發現了瀏覽器的使用率部分的第二部分:https://github.com/podio/podio-js#browser


podio-js文件夾中:

npm install -g browserify 
npm run bundle 

然後在您的HTML頁面中使用標籤包含dist/podio-js.js

注意:一旦你綁定了源代碼,你可以複製粘貼編譯的文件到你想要的任何地方。