【发布时间】:2018-01-21 16:41:05
【问题描述】:
我正在尝试编写一个使用谷歌网址缩短器的服务,但遇到了问题 以下是我的服务:
urlShortener(longUrl: string): Observable<string> {
let body = {longUrl: longUrl}
let options = {
params: {key: XXXXXX},
};
return this.http.post('https://www.googleapis.com/urlshortener/v1/url', body, options)
.map(response => {
console.debug('response',response);
return response;
})
.catch(this.handleError);
}
来自谷歌 API 的错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
API key 没有错误,因为用 angular1 编写的相同代码返回的是 shortUrl
【问题讨论】:
标签: angular google-url-shortener