这是我的代码
gettheLinkedinUserDetails(token: string) {
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
headers.append('Authorization','Bearer '+token);
this.http.get('https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url)?format=json',{headers: headers})
.subscribe(profileData => {
alert(profileData + 'hii');
})
}
我正在使用HttpClientModule
并且出现错误消息
Argument of type '{ headers: Headers; }' is not assignable to parameter of type '{ headers?: HttpHeaders | { [header: string]: string | string[]; }; observe?: "body"; params?: HttpParams | { [param: string]: string | string[]; }; reportProgress?: boolean; responseType?: "json"; withCredentials?: boolean; }'.
Types of property 'headers' are incompatible.
Type 'Headers' is not assignable to type 'HttpHeaders | { [header: string]: string | string[]; }'.
Type 'Headers' is not assignable to type '{ [header: string]: string | string[]; }'.
Index signature is missing in type 'Headers'.
我该如何解决这个问题?
答案 0 :(得分:0)
使用HttpHeaders
代替Headers
中的@angular/common/http
。
gettheLinkedinUserDetails(token: string) {
let headers: new HttpHeaders(
{ 'Content-Type': 'application/x-www-form-urlencoded' },
{ 'Authorization','Bearer ' + token });
this.http.get('https://api.linkedin.com/v1/people/~:(id,first-name,last-name,email-address,picture-url)?format=json',
{headers: headers})
.subscribe(profileData => {
alert(profileData + 'hii');
});
}