[英]Unable to connect Google Apps Script to Plaid API
怎么了团队,我正在尝试使用 Plaid 自动填充 Google 表格,其中包含在我的 Plaid 帐户中设置的财务报表。 我最近看到一些公司这样做是收费的(例如https://www.budgetsheet.net/ )。 几年前我还看到开发人员完成了它(参见https://github.com/hirefrank/plaid-txns-google-sheets )。 这就是我想要做的,但是格子 API 从那时起已经更新以从使用中删除公钥来代替链接令牌: https://plaid.com/docs/link/link-token-migration-guide/
工作流程应该如下:
我可以通过以下调用创建 link_token(链接令牌位于responseJSON.link_token ):
/************************************************************************************
*
* Creating function to get access token
*
************************************************************************************/
function getLinkToken(CLIENT_ID, SECRET) {
// Specify headers
var headers = {
'Content-Type': 'application/json',
};
// Build data for link token
var data = {
'client_id': CLIENT_ID,
'secret': SECRET,
"client_name": "ryanmcslomo",
"products": ["auth", 'transactions'],
"language": "en",
"country_codes": ["US"],
"user": {
// "client_user_id": "unique-per-user",
"client_user_id": "ryanmcslomo",
},
};
// Build params
var parameters = {
'headers': headers,
'payload': JSON.stringify(data),
'method': 'post',
'muteHttpExceptions': true,
};
// Call link token API with params
var url = "https://development.plaid.com/link/token/create";
var response = UrlFetchApp.fetch(url, parameters);
var responseJSON = JSON.parse(response);
//Return JSON containing Link Token
return responseJSON;
}
但在那之后,我不确定如何使用链接令牌初始化链接(更不用说获取公共令牌以交换访问令牌)。 当我尝试将链接令牌作为公共令牌传递来进行身份验证时,它(当然)失败了:
// Build data for access token
var data2 = {
'client_id': CLIENT_ID,
'secret': SECRET,
"public_token": responseJSON.link_token
};
// Build params
var parameters2 = {
'headers': headers,
'payload': JSON.stringify(data2),
'method': 'post',
'muteHttpExceptions': true,
};
// Call API with params
var url2 = "https://development.plaid.com/item/public_token/exchange";
var response2 = UrlFetchApp.fetch(url2, parameters2);
var response2JSON = JSON.parse(response2);
// return JSON response with Link Token
return response2JSON;
}
响应2JSON:
{
display_message: null
documentation_url: "https://plaid.com/docs/?ref=error#invalid-input-errors"
error_code: "INVALID_PUBLIC_TOKEN"
error_message: 'provided token is the wrong type. expected "public", got "link"'
error_type: " INVALID_INPUT"
...
}
有任何想法吗? 不确定如何作为 Google Apps 脚本执行此操作。 谢谢您的帮助!
我看过的其他地方:
我实际上正在做一些非常相似的事情。 我发现最简单的方法是使用快速入门来生成 access_token 并将其传递到我在应用程序脚本中的请求中。
使用 web 上的链接令牌初始化链接:
const handler = Plaid.create({
token: 'GENERATED_LINK_TOKEN',
onSuccess: (public_token, metadata) => {},
onLoad: () => {},
onExit: (err, metadata) => {},
onEvent: (eventName, metadata) => {},
receivedRedirectUri: null,
});
触发对 /item/public_token/exchange 的调用:
onSuccess: (public_token, metadata) => {
fetch('//yourserver.com/get_access_token', {
method: 'POST',
body: {
public_token: public_token,
accounts: metadata.accounts,
institution: metadata.institution,
link_session_id: metadata.link_session_id,
},
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.