我正在使用 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(){
}
}
最佳答案
编辑:
您不需要从http.get()
映射
您的响应对象。它是由新的 angular6 http
自动完成的。
所以应该是这样的:
this.http.get(authURL).subscribe((res:any)=> {console.log("Http Get "+ res); });
与CORS
相关的原始答案:
正如 answer 中所建议的那样,尝试从后端 api 而不是直接从浏览器调用 linkedIn api
。这将解决您的跨源
相关问题。
Linkedin
将直接不允许任何第三方应用程序执行其 api
。它必须来自您的后端 api
本身,而不是浏览器。
关于angular - 点击 linkedin 的 http get 请求,在 Angular 2 中给出错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52179560/