这里-API 401 : "Invalid app_id app_code combination"
Here-API 401 : "Invalid app_id app_code combination"
我正在使用带有 Nodejs 后端的 Angular 前端。我目前通过我的快递服务器代理我所有的前端请求。但是,当我向此处 API 发出 http 请求时,由于 app_id 和 app_code.
的组合无效,我被拒绝了
angular 服务
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { HttpParams } from '@angular/common/http'
@Injectable({
providedIn: 'root'
})
export class GetReqPlaces {
constructor(private http: HttpClient) { }
getPlaces(wLong,sLat,eLong,nLat){
// let obj = {params: {westLong: wLong, southLat: sLat, eastLong:eLong, northLat:nLat }};
let params = new HttpParams().set("westLong" , '-97.783').set("southLat", '30.231').set( "eastLong" , '-97.740').set("northLat", '30.329');
return this.http.get( 'api/find/places', { params : params}).subscribe(res=>console.log(res))
}
}
server.js
const express = require("express")
const bodyParser = require("body-parser")
const cors = require("cors")
const path = require("path")
const app = express();
const request = require("request")
const environment= require('./keys')
app.use(cors());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
let reqPath = __dirname.substring(0,__dirname.length-7)
app.use(express.static(path.join(reqPath, '/dist/angular-places-search')));
app.get('/api/find/places', (req, res) => {
let appId = environment.environment.appId;
let appCode = environment.environment.appCode;
let URL= `https://places.cit.api.here.com/places/v1/discover/search?app_id={${appId}}&app_code={${appCode}}&in=${req.query.westLong},${req.query.southLat},${req.query.eastLong},${req.query.northLat}&pretty`;
console.log(URL)
request(URL, function (error, response, body) {
let data={
body:body,
};
console.log(error,response)
res.send(data);
});
});
app.get('/test', (req, res) => res.send('Well this route was a hit! Bada....tsss'));
// CATCH ALL
app.get('*', (req, res) => {
res.sendFile(path.join(reqPath, 'dist/angular-places-search/index.html'));
});
app.listen(4000, () => console.log(`Express server running on port 4000`));
在此之前,我 运行 关注 CORS 和请求问题,但我想我已经解决了这些问题。根据我对相同错误代码的研究(在我工作的框架的上下文中),绝大多数人建议等待令牌在 Here API 上注册。我想等两天就够了,还是不行。然后是非常流行的解决方案,即只使用 Here 免费增值服务并开始一个新项目,我这样做了,但没有解决我的问题。很少有事情我有 100% 的把握,但我确实正确地复制了我的密钥,并且 URL 路径是根据所需的 Here 语法构建的。
如果有人有任何见解,你将是我的英雄,也是我继续学习的催化剂:D。周日快乐!
此外,我通过快递收到的消息是:
method: 'GET',
path: '/places/v1/discover/search?app_id=%notmyid%7D&app_code=%normycode%7D&in=-97.783,30.231,-97.740,30.329&pretty'
但是我不知道为什么它设置 app_id=% 而不是使用 {},当我控制台记录 URL 它是正确的,我的 app_id 和 app_code
%7D 是符号的 url 编码值 } (urlencoding) which is done by most libraries. For using the HERE API you should not enclose the app_id/app_code between {}. They should be provided directly as strings, check the examples
我正在使用带有 Nodejs 后端的 Angular 前端。我目前通过我的快递服务器代理我所有的前端请求。但是,当我向此处 API 发出 http 请求时,由于 app_id 和 app_code.
的组合无效,我被拒绝了angular 服务
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http'
import { HttpParams } from '@angular/common/http'
@Injectable({
providedIn: 'root'
})
export class GetReqPlaces {
constructor(private http: HttpClient) { }
getPlaces(wLong,sLat,eLong,nLat){
// let obj = {params: {westLong: wLong, southLat: sLat, eastLong:eLong, northLat:nLat }};
let params = new HttpParams().set("westLong" , '-97.783').set("southLat", '30.231').set( "eastLong" , '-97.740').set("northLat", '30.329');
return this.http.get( 'api/find/places', { params : params}).subscribe(res=>console.log(res))
}
}
server.js
const express = require("express")
const bodyParser = require("body-parser")
const cors = require("cors")
const path = require("path")
const app = express();
const request = require("request")
const environment= require('./keys')
app.use(cors());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.json());
let reqPath = __dirname.substring(0,__dirname.length-7)
app.use(express.static(path.join(reqPath, '/dist/angular-places-search')));
app.get('/api/find/places', (req, res) => {
let appId = environment.environment.appId;
let appCode = environment.environment.appCode;
let URL= `https://places.cit.api.here.com/places/v1/discover/search?app_id={${appId}}&app_code={${appCode}}&in=${req.query.westLong},${req.query.southLat},${req.query.eastLong},${req.query.northLat}&pretty`;
console.log(URL)
request(URL, function (error, response, body) {
let data={
body:body,
};
console.log(error,response)
res.send(data);
});
});
app.get('/test', (req, res) => res.send('Well this route was a hit! Bada....tsss'));
// CATCH ALL
app.get('*', (req, res) => {
res.sendFile(path.join(reqPath, 'dist/angular-places-search/index.html'));
});
app.listen(4000, () => console.log(`Express server running on port 4000`));
在此之前,我 运行 关注 CORS 和请求问题,但我想我已经解决了这些问题。根据我对相同错误代码的研究(在我工作的框架的上下文中),绝大多数人建议等待令牌在 Here API 上注册。我想等两天就够了,还是不行。然后是非常流行的解决方案,即只使用 Here 免费增值服务并开始一个新项目,我这样做了,但没有解决我的问题。很少有事情我有 100% 的把握,但我确实正确地复制了我的密钥,并且 URL 路径是根据所需的 Here 语法构建的。
如果有人有任何见解,你将是我的英雄,也是我继续学习的催化剂:D。周日快乐!
此外,我通过快递收到的消息是:
method: 'GET',
path: '/places/v1/discover/search?app_id=%notmyid%7D&app_code=%normycode%7D&in=-97.783,30.231,-97.740,30.329&pretty'
但是我不知道为什么它设置 app_id=% 而不是使用 {},当我控制台记录 URL 它是正确的,我的 app_id 和 app_code
%7D 是符号的 url 编码值 } (urlencoding) which is done by most libraries. For using the HERE API you should not enclose the app_id/app_code between {}. They should be provided directly as strings, check the examples