2013-06-18 34 views

回答

49

可以在2的一個方式做到這一點 -

將用戶引導到下面的地址。這將引導用戶訪問具有可以複製並粘貼回給您的令牌的頁面。最重要的一點是,你要求expiration = neverscope = read,write

https://trello.com/1/authorize?key=substitutewithyourapplicationkey&scope=read%2Cwrite&name=My+Application&expiration=never&response_type=token 

或者使用OAuth(難)自動訪問令牌的請求。詳情請參閱documentation

一旦你有了令牌,你可以進行任何你想要的API調用。

+1

鏈接到文檔頁面:https://trello.com/docs/gettingstarted/index.html#getting-a-token-from-a-user –

10

如果你必須做一切服務器端,安迪瓊斯是正確的,那些是唯一的兩種方式。

但是,應該注意的是,如果您可以編寫javascript + jquery代碼而不必執行重定向服務器端,則可以利用Trello的client.js包裝器,它完全符合Andy所描述的內容,但照顧它的大部分給你,這是方便的方式。

而且,正如我最近發現的,如果您確實需要處理服務器端,您仍然可以使用client.js,然後在auth成功處理程序中使用Trello.token()獲取令牌,並通過即你的服務器端代碼。它看起來像這樣:

// include whatever version of jquery you want to use first 
<script src="https://api.trello.com/1/client.js?key=[your application key]" type="text/javascript"></script> 

// call this whenever you want to make sure Trello is authenticated, and get a key. 
// I don't call it until the user needs to push something to Trello, 
// but you could call it in document.ready if that made more sense in your case. 
function AuthenticateTrello() { 
     Trello.authorize({ 
      name: "your project name", 
      type: "popup", 
      interactive: true, 
      expiration: "never", 
      success: function() { onAuthorizeSuccessful(); }, 
      error: function() { onFailedAuthorization(); }, 
      scope: { write: true, read: true }, 
     }); 
} 

function onAuthorizeSuccessful() { 
    var token = Trello.token(); 
    // whatever you want to do with your token. 
    // if you can do everything client-side, there are other wrapper functions 
    // so you never need to use the token directly if you don't want to. 
} 

function onFailedAuthorization() { 
    // whatever 
} 
+0

這非常有幫助。非常感謝。 – Lokesh

0

如果你只需要供個人使用的令牌可以app-keysecrettoken根據你被記錄在了here得到。