Power BI Access Token API无法在Angular中运行

时间:2017-11-28 13:17:19

标签: javascript angularjs powerbi powerbi-embedded

尝试将PowerBI仪表板嵌入角度应用程序中。用于获取访问令牌的API调用在API中工作正在Postman中工作但在Angular $ http.post中不起作用

这是我的http请求:

correlation_id : "1e68335a-6b6d-441d-90d3-eb8c88929a37"
    error:"invalid_request"
    error_codes:[90014]
    error_description:"AADSTS90014: The request body must contain the following parameter: 'grant_type'.
    ↵Trace ID: 5f039662-e0ce-425a-9e38-1593c64c7b00
    ↵Correlation ID: 1e68335a-6b6d-441d-90d3-eb8c88929a37
    ↵Timestamp: 2017-11-28 12:39:05Z"
    timestamp:"2017-11-28 12:39:05Z"
    trace_id:"5f039662-e0ce-425a-9e38-1593c64c7b00"

回应是:

public void startAnimation() {


        ValueAnimator anim = ValueAnimator.ofFloat(oldmSweepAngle, mEndAngle);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator valueAnimator) {
                ProgressCircle.this.mSweepAngle = (Float) valueAnimator.getAnimatedValue();
                   ProgressCircle.this.invalidate();
            }
        });
        anim.setDuration(500);
        anim.setInterpolator(new AccelerateDecelerateInterpolator());
        anim.start();

    }

}

任何人都可以帮助我摆脱这个障碍吗?

1 个答案:

答案 0 :(得分:0)

我得到了解决方案。我得到了错误,我正在进行API调用。它希望数据以“内容类型”和“应用程序/ x-www-form-urlencoded'并且数据被序列化。

此代码有效:

$http({
      headers: {'Content-Type':'application/x-www-form-urlencoded; charset=UTF-8'},
      url: 'https://login.microsoftonline.com/common/oauth2/token',
      method: 'POST',
      transformRequest: $httpParamSerializer,
      transformResponse: function (x) {
        return angular.fromJson(angular.fromJson(x));
      },
      data: {
        grant_type:'password',
        client_id: "client_id",
        resource:'https://analysis.windows.net/powerbi/api',
        username:"username",
        password: "pwd",
        client_secret: "client_secret"
      }
  }) 

我希望这个答案对将来遇到同样问题的人有用。