goo.gl urlshortener request works on localhost only

98 Views Asked by At

I have a urlshortener code working when I am on localhost but won't work if deployed elsewhere (or if I access my local app via the IP address) :

Here is my code :

    insertUrl(longUrl) {
    let headers = new Headers({
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    });
    let body = {
        'longUrl': longUrl
    };
    let options = new RequestOptions({
        method: RequestMethod.Post,
        headers: headers,
        body: body
    });
    return this.http.post(UrlShortener.URL_SHORTENER_API + '?key=' + '<MY APY KEY>', body, options)
                .map((res: Response) => res.json());

}

It is probably a very easy answer to this but I cannot figure it out. Any help appreciated !

The error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value",
    "locationType": "parameter",
    "location": "resource.longUrl"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}
0

There are 0 best solutions below