습득 조건 : https://code.google.com/apis/console/js에서 URL을 어떻게 단축합니까?
JS를 통해 원래의 URL로 get API를 goo.gl URL을 바꾸는 다양한 방법에 대한 문서가 많이가 있습니다에서 자신에게 urlshortener에 대한 API 키를 생성 예 : here, here 및 here - - 적어도 첫 번째 작품은 작동합니다. 내가 대신 { "longUrl": "https://codepen.io/" }
를 전달에 URL을 작은 URL을 을 변환 할 insert API를 사용하려면 약간 어느 하나를 조정할 경우
하지만, 그것은 나누기. 만약 당신이 좋아하면 http://codepen.io/johan/full/EHbGy#YOUR-API-KEY-HERE에서 그것을 시도, 또는이 어딘가에 실행 오류와 함께
<script>
var api_key = 'YOUR-API-KEY-HERE';
function makeRequest() {
var request = gapi.client.urlshortener.url.insert({
'longUrl': 'https://codepen.io/'
});
request.execute(function(response) {
alert(JSON.stringify(window.got = response));
});
}
function load() {
gapi.client.setApiKey(api_key);
gapi.client.load('urlshortener', 'v1', makeRequest);
}
</script>
<script src="https://apis.google.com/js/client.js?onload=load"></script>
... 그냥 응답을 :
{ "code": 400
, "message": "Required"
, "data":
[ { "domain": "global"
, "reason": "required"
, "message": "Required"
, "locationType": "parameter"
, "location": "resource.longUrl"
}
]
, "error":
{ "code": 400
, "message": "Required"
, "data":
[ { "domain": "global"
, "reason": "required"
, "message": "Required"
, "locationType": "parameter"
, "location": "resource.longUrl"
}
]
}
}
제안? (아니요, resource.longUrl
키가있는 객체에 url.insert
매개 변수를 변경하거나 래퍼 객체없이 URL 만 전달하면 더 이상 작동하지 않습니다.
감사합니다. 좋은 문서를 유지하는 것은 좋은 API를 만드는 것만 큼 어렵습니다. – ecmanaut
@ecmanaut'URL Resource'의 예제 링크가 도움이되지 않았다는 것을 의미합니까? https://developers.google.com/url-shortener/v1/url/url#resource – doublesharp
developers.google.com이 (사용자가 Google 웹 마스터 도구를 사용하여) 404 명의 사용자를 분류 할 수있는 기회를 제공합니다. . 나는 끊임없는 전임 QA의 위치라는 것을 알 수 있었다. – ecmanaut