angular6-我无法从Scopus API获得响应

时间:2018-07-12 18:59:12

标签: httpresponse angular6 scopus

我想使用Scopus API验证DOI是否存在。我正在使用“ Cited By”选项。我对http://api.elsevier.com/content/search/scopus?query=DOI(10.1016/j.stem.2011.10.002)中的“ POSTMAN”链接进行了测试,并且可以正常工作,但是当我在Angular this is what returns中进行实现时。

角度代码

let headers = new Headers({ 
            'X-ELS-APIKey': apikey,
            'Accept': 'application/json',
        });
        this._http.get('http://api.elsevier.com/content/search/scopus?query=DOI(' + doi + ')', { headers: headers }).pipe(map(res => res.json())).subscribe(
            response => {
                console.log("Response");
                console.log(response);
            },
            error => {
                console.log("Error");
                console.log(error);
            }
        );

非常感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

最后,我解决了这个问题,问题是“ doi”字符串需要通过encodeURIComponent()函数。我留下了代码,以防有人需要。

welcome.component.ts

let doi = encodeURIComponent('10.1017/j.stem.2011.10.002');
this._scopusService.getPublication(doi).subscribe(
    response => {
    console.log("DOI exists");
},
error => {
    console.log("DOI doesn't exists");
}

scopus.service.ts

public getPublication(doi) {
    let headers = new Headers({
        'Accept': 'application/json',
        'X-ELS-APIKey': this.apiKey
    });

    return this._http.get('https://api.elsevier.com/content/search/scopus?query=DOI(' + doi + ')', { headers: headers }).pipe(map(res => res.json()));
}