【问题标题】:Google URL Shortener API -Google URL Shortener API -
【发布时间】:2017-02-09 11:58:21
【问题描述】:

API 新手...我正在查看此处的文档 (https://developers.google.com/url-shortener/v1/getting_started),但无法使用以下命令:

  curl https://www.googleapis.com/urlshortener/v1/url?key=<MYAPIKEY> \
  -H 'Content-Type: application/json' \
  -d '{"longUrl": "http://www.google.com/"}'

收到此错误消息:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "required",
    "message": "Required parameter: shortUrl",
    "locationType": "parameter",
    "location": "shortUrl"
   }
  ],
  "code": 400,
  "message": "Required parameter: shortUrl"
 }
}

不知道他们为什么要一个 shortUrl 参数,这不是我要他们返回给我的吗?

【问题讨论】:

    标签: curl google-api short-url


    【解决方案1】:

    这是一个正确的例子,你可能做错了什么。 API 工作正常,并使用您提供的示例缩短了 URL。

    您确定您没有在第一个反斜杠 (\) 处完成命令的执行,因为如果您这样做,它将返回您遇到的错误。确保一次运行整个命令。您还可以将多行合二为一并删除反斜杠。

    因此运行此命令(不提供内容和 HTTP 标头):

    curl https://www.googleapis.com/urlshortener/v1/url?key=<MYAPIKEY>
    

    会返回以下错误:

    {
     "error": {
      "errors": [
       {
        "domain": "global",
        "reason": "required",
        "message": "Required parameter: shortUrl",
        "locationType": "parameter",
        "location": "shortUrl"
       }
      ],
      "code": 400,
      "message": "Required parameter: shortUrl"
     }
    }
    

    【讨论】:

    • 发誓我以前试过,但这次成功了——谢谢! :)
    猜你喜欢
    • 2016-02-26
    • 1970-01-01
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多