在 angular 2 中点击 linkedin 的 http get 请求给出错误
Hitting the http get request for linkedin giving error in angular 2
我正在使用 linkedin 进行注册,需要获取访问代码和基本个人资料详细信息。但是当我 post 请求时,我在控制台中收到 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(){
}
}
编辑:
您不需要 map
来自 http.get()
的响应对象。它由 new angular6 http
.
自动完成
所以应该是这样:
this.http.get(authURL).subscribe((res:any)=> {console.log("Http Get " + res); });
与CORS
相关的原始答案:
按照 中的建议,尝试从后端 api 而不是直接从浏览器调用 linkedIn api
。这将解决您的 Cross origin
相关问题。
Linkedin
将直接不允许任何第三方应用程序执行其api
。它必须来自您的后端 api
本身,而不是浏览器。
我正在使用 linkedin 进行注册,需要获取访问代码和基本个人资料详细信息。但是当我 post 请求时,我在控制台中收到 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(){
}
}
编辑:
您不需要 map
来自 http.get()
的响应对象。它由 new angular6 http
.
所以应该是这样:
this.http.get(authURL).subscribe((res:any)=> {console.log("Http Get " + res); });
与CORS
相关的原始答案:
按照 linkedIn api
。这将解决您的 Cross origin
相关问题。
Linkedin
将直接不允许任何第三方应用程序执行其api
。它必须来自您的后端 api
本身,而不是浏览器。