【问题标题】:Connect apiary.io REST API v1+ in Google Data Studio在 Google Data Studio 中连接 apiary.io REST API v1+
【发布时间】:2019-06-28 01:09:17
【问题描述】:

我需要将apiary.io REST API v1+ 连接到Google Data Studio

正如我检查的那样,我需要在Google Apps Script 中开发一个带有JavaScript 的连接器,正如我在这些教程Connect and visualize all your data in Data StudioExternal APIs 中检查的那样。

在这一步一步的软件制造商,piperun REST API v1+。有几个代码 sn-ps,但我不能让它们在GDS 中工作。

很遗憾我对JavaScript没有太多经验,我的主要技能是T-SQL,但我可以在Microsoft PowerBI上建立成功的联系。但是我能够通过插入URLsTOKENSof 访问权限在Microsoft PowerBI 中成功建立连接,返回码为200

function teste() {

  var url = 'https://api.pipe.run/v1/activities';

  var request = UrlFetchApp;

  request.fetch(url); 

  request.onreadystatechange = function () {
  if (this.readyState === 4) {
      console.log('Status:', this.status);
      console.log('Headers:', this.getAllResponseHeaders());
      console.log('Body:', this.responseText);
    }
  };

  request.send();

  var request = new XMLHttpRequest();

  request.open('GET', 'https://api.pipe.run/v1/activities/activity_id');

               request.setRequestHeader('Content-Type', 'application/json');
  request.setRequestHeader('Token', 'Q3VydGl1IGVzc2Ugam9iPyEgdHJhYmFsaGVjb25vc2NvQHBpcGUucnVu'); // Here I add TOKEN supplied internally by the application

  request.onreadystatechange = function () {
    if (this.readyState === 4) {
      console.log('Status:', this.status);
      console.log('Headers:', this.getAllResponseHeaders());
      console.log('Body:', this.responseText);
    }
  };

  request.send();  
}

而且即使你输入了一个有效的TOKEN,也会出现错误:

请求 https://api.pipe.run/v1/activities 失败,返回代码 401。截断的服务器响应:{"success": false, "message": "Unauthorized"}(使用 muteHttpExceptions 选项检查完整答案)(第 8 行,文件“代码")

所以我想知道是否有其他简单的方法或者我需要学习什么才能建立与apiary.io REST API v1+ 的连接。

【问题讨论】:

  • 查看urlfetchapp官方文档和FAQhere

标签: javascript google-apps-script google-data-studio urlfetch apiary.io


【解决方案1】:

在朋友开发者的帮助下,我们用以下方案解决:

   function myFunction() {

      var token = 'Q3VydGl1IGVzc2Ugam9iPyEgdHJhYmFsaGVjb25vc2NvQHBpcGUucnVu'
      var url = 'https://api.pipe.run/v1/deals'
      var params = { method:"GET",
                    headers:{Token: token,
                            contentType:'application/json',}
                    };

     var response = UrlFetchApp.fetch(url, params);

     var json = response.getContentText();
     var data = JSON.parse(json);
     Logger.log(response.getContentText());

    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-07
    • 2018-05-03
    • 2019-09-04
    • 2016-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-29
    相关资源
    最近更新 更多