Google Apps Script 与 Saxo Trader 的集成

问题描述

我想使用 Google Apps 脚本创建一个程序,该程序允许我从 Saxo@R_502_5705@er 检索价格,并使用他们的模拟账户进行交易。我被困在授权步骤。我似乎无法获得授权/访问权限。 它说访问被拒绝。我不知道为什么?有人可以帮助我吗?谢谢!

var clientID = "....."
var clientSecret = "....."
var authorizationBaseUrl = "https://sim.logonvalidation.net/authorize" 
var tokenUrl = "https://sim.logonvalidation.net/token" 
// Refer to notes from "https://www.developer.saxo/openapi/learn/oauth-authorization-code-grant"


//Create the OAuth2 service
function getService() {
  return OAuth2.createService('Saxo')
  // Set the endpoint URLs
  .setAuthorizationBaseUrl(authorizationBaseUrl)
  .setTokenUrl(tokenUrl)
  
  // Set the client ID and secret
  .setClientId(clientID)
  .setClientSecret(clientSecret)
  
  // Set other parameters required by Saxo
  .setParam('response_type','code')
  
  //Set the name of callback function to be invoked to complete OAuth flow.
  .setCallbackFunction("authCallback")
  
  //Set the property story where authorized tokens should be persisted
  .setPropertyStore(PropertiesService.getUserProperties());
}

// Direct the user to the authorization URL
function showSidebar() {
  var service = getService();
  if (!service.hasAccess()) {
    var authorizationUrl = service.getAuthorizationUrl();
    var template = HtmlService.createTemplate(
      '<a href="<?= authorizationUrl ?>" target="_blank">Authorize</a>. ' +
      'Reopen the sidebar when the authorization is complete.');
    template.authorizationUrl = authorizationUrl;
    var page = template.evaluate();
    SpreadsheetApp.getUi().showSidebar(page);
  } else {
    //...
  }
}

//Handles the OAuth callback
function authCallback(request) {
  var service = getService();
  var authorized = service.handleCallback(request);
  if (authorized) {
    return HtmlService.createHtmlOutput("Success!");
  } else {
    return HtmlService.createHtmlOutput("Denied!");
  }
}

//Get the access token and make requests to the API
function makerequest() {
  var service = getService();
  var response = UrlFetchApp.fetch("https://gateway.saxobank.com/sim/openapi/port/v1/users/me",{
    headers: {
      Authorization: 'Bearer ' + service.getAccesstoken()
    }
  });
  var results = JSON.parse(response.getContentText());
  SpreadsheetApp.getActiveRange().setValues(results);  
}

// Logs the redirect URI to register
function logRedirectUri() {
  Logger.log(OAuth2.getRedirectUri());
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)