power bi access token api在邮递员中工作正常,但在角度应用程序中不工作 [英] power bi access token api working fine in postman but not working in angular app

查看:15
本文介绍了power bi access token api在邮递员中工作正常,但在角度应用程序中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在邮递员中调用 power bi API,它运行良好,并且作为我得到的公认结果.当我在角度应用程序中调用该应用程序时,它不起作用.我的响应为空.

我在下面附上了我的代码,请帮帮我,我最近几天一直在尝试解决这个问题.

API:

解决方案

我得到了问题和解决方案.

问题:
为什么它破坏了我的 API 响应null".问题是由于 CORS,我使用了 crome 的 CORS 扩展,它已被弃用.所以它的结果是'null'

解决方案:
我为 chrome 使用了最新的一个 CORS 扩展,这暂时解决了这个问题.这不是一个合适的解决方案,因为我们无权在后端解决 cors 问题.如果我们需要自己解决它,那么我们必须在 .net 中创建 API 以获取 AccessToken,然后我们可以在 Angular 中使用该 API.

I'm calling power bi API in postman which is working good and as an accepted result I'm getting. while that app I'm calling in the angular app it's not working. I'm getting response null.

I have attached my code below, Please help me out I have been trying to solve this issue last few days.

API: https://login.microsoftonline.com/common/oauth2/token

Below is my angular code

getAccessToken(param): Observable<any> {

const httpOptions = {
  headers: new HttpHeaders({
    'Content-Type': 'application/x-www-form-urlencoded',
  })
};

const body = new HttpParams()
  .set('resource', 'https://analysis.windows.net/powerbi/api')
  .set('client_id', 'xxxxxxxxx')
  .set('client_secret', 'xxxxxxxxx')
  .set('grant_type', 'password')
  .set('scope', 'openid')
  .set('username', 'xxxxxxxxx')
  .set('password', 'xxxxxxxxx');

return this.http.post("https://login.microsoftonline.com/common/oauth2/token", body.toString(), httpOptions)
  .pipe(
    map(response => response)
  );}

In the below reference image same API which is working good but not working in angular.

解决方案

I got the issue and solution.

Issue:
why it's broken my API response 'null'. The issue is that due to CORS, I used the CORS extension for crome it was deprecated. so it was given the result 'null'

Solution:
I used the latest one CORS extension for chrome and that's resolved the issue temporarily. this is not a proper solution because we don't have the right to resolved cors issue in the backend. if we need to solve it form our hand then we have to create API in .net for getting AccessToken and then that API we can consume in Angular.

这篇关于power bi access token api在邮递员中工作正常,但在角度应用程序中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆