【发布时间】:2019-02-10 06:29:24
【问题描述】:
我正在使用linkedin 进行注册,需要获取访问代码和基本个人资料详细信息。但是当我发布请求时,我在控制台中收到 CORS 错误,当我直接在浏览器中点击 URL 时,它会将我正确带到登录页面。遇到请求会有什么问题?
CORS 问题已解决:
我发现 localhost:4200 没有 '/' 并且在包含它之后,CORS 错误已解决,但点击我的 http.get 有问题 组件:
import { Injectable } from '@angular/core';
import {Http} from '@angular/http';
import {Observable} from 'rxjs';
import {map} from 'rxjs/operators'
import { mapToExpression } from '../../../node_modules/@angular/compiler/src/render3/view/util';
@Injectable({
providedIn: 'root'
})
export class LinkedInService {
constructor(private http:Http) {
console.log("In Linked in constructor");
}
public linkedInSignIn(){
console.log ("Linked in Sign in");
let authURL ="https://www.linkedin.com/oauth/v2/authorization?"+// "https://www.linkedin.com/uas/oauth2/authorization?"+
"response_type=code"+
"&client_id=781872"+
"&state=xys"+
"&redirect_uri=http://localhost:4200/";
console.log("auth rul" +authURL);
this.http.get(authURL).pipe(map(res => res.json()))
.subscribe((res:Response)=>{
console.log("Http Get " + res);
});//people => this.people = people);
}
public linkedInSignOut(){
}
}
【问题讨论】:
-
你能试着删除这个 .pipe(map(res => res.json())) 看看你得到什么回应吗?
-
如果我删除它,我会收到此错误“(res:响应)=> void”类型的参数不可分配给“(值:响应)=> void”类型的参数。参数“res”和“value”的类型不兼容。类型 'import("f:/recipeBook/node_modules/@angular/http/src/static_response").Response' 不可分配给类型 'Response'。 “响应”类型中缺少“重定向”属性。
标签: angular angular2-services linkedin-api