Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取访问令牌的google脚本中的curl语法_Curl_Google Apps Script_Google Sheets - Fatal编程技术网

获取访问令牌的google脚本中的curl语法

获取访问令牌的google脚本中的curl语法,curl,google-apps-script,google-sheets,Curl,Google Apps Script,Google Sheets,我不熟悉使用API连接来使用Google脚本将数据输入Google工作表 如何在Google脚本中编写下面的CURL请求? curl -u {client_id}:{client_secret} \ https://api.podbean.com/v1/oauth/token \ -X POST -d 'grant_type=authorization_code&code={code}&redirect_uri={your_redirect_uri}' 这个呢 c

我不熟悉使用API连接来使用Google脚本将数据输入Google工作表

如何在Google脚本中编写下面的CURL请求?

curl -u {client_id}:{client_secret} \
 https://api.podbean.com/v1/oauth/token \
  -X POST -d 'grant_type=authorization_code&code={code}&redirect_uri={your_redirect_uri}'
这个呢

    curl https://api.podbean.com/v1/analytics/podcastReports \
  -G -d 'access_token={access_token}' -d 'podcast_id={podcast_id}' -d 'year=2018'

我相信你的目标如下

  • 您希望将以下2个curl命令转换为Google Apps脚本

  • Curl命令1

     curl -u {client_id}:{client_secret} \
     https://api.podbean.com/v1/oauth/token \
     -X POST -d 'grant_type=authorization_code&code={code}&redirect_uri={your_redirect_uri}'
    
  • Curl命令2

     curl https://api.podbean.com/v1/analytics/podcastReports \
     -G -d 'access_token={access_token}' -d 'podcast_id={podcast_id}' -d 'year=2018'
    
Curl命令1的示例脚本: Curl命令2的示例脚本: 注:
  • 在使用上述脚本之前,请再次确认脚本中的
    客户id
    客户机密
    代码
    重定向uri
    访问令牌
    播客id
    年份

  • 关于“Curl命令2的示例脚本”,当特殊字符包含在
    access_-token
    podcast_-id
    的值中时,请使用
    encodeURIComponent()
    const-url=`${baseUrl}?access_-token=${encodeURIComponent(access_-token)}和podcast_-id=${encodeURIComponent(podcast_-id)}&年份=${year}`

参考:

我不得不为我糟糕的英语技能道歉。很遗憾,我不能理解你的问题。我为此道歉。那么,我能问一下你的问题吗?您的问题是
如何在Google脚本中编写CURL请求以获取访问令牌?
?或者,你的问题有几个问题?@Tanaike-不,我把问题弄得太复杂了。我会编辑它。如果你能建议如何在谷歌脚本中编写CURL请求,这将对我有很大帮助。谢谢你回复和更新你的问题。根据你最新的问题,我提出了一个答案。你能确认一下吗?在我的环境中,我可以用curl命令确认每个脚本的请求都是相同的。但是,当您测试脚本时出现错误,我向您道歉。当时,你能提供错误信息吗?@Tanaike genius。非常感谢你!谢谢你的回复。我很高兴你的问题解决了。也谢谢你。
function sample1() {
  // Please set your values to the following variables.
  const client_id = "your client_id";
  const client_secret = "your client_secret";
  const code = "your code";
  const redirect_uri = "your redirect_uri";

  const params = {
    method: "post",
    payload: {
      grant_type: "authorization_code",
      code: code,
      redirect_uri: redirect_uri
    },
    headers: {Authorization: "Basic " + Utilities.base64Encode(`${client_id}:${client_secret}`)},
    muteHttpExceptions: true
  };
  const url = "https://api.podbean.com/v1/oauth/token";
  const res = UrlFetchApp.fetch(url, params);
  console.log(res.getContentText())
}
function sample2() {
  // Please set your values to the following variables.
  const access_token = "your access_token";
  const podcast_id = "your podcast_id";
  const year = "2018";

  const baseUrl = "https://api.podbean.com/v1/analytics/podcastReports";
  const url = `${baseUrl}?access_token=${access_token}&podcast_id=${podcast_id}&year=${year}`;
  const res = UrlFetchApp.fetch(url, {muteHttpExceptions: true});
  console.log(res.getContentText())
}