异常时,Facebook Graph API总是返回错误的请求错误

时间:2018-09-18 04:43:31

标签: facebook-graph-api bad-request

当我使用Graph API Explore调用API时 它返回错误代码和明确的消息

<div #imageList>
</div>
import { Component, OnInit, ElementRef } from '@angular/core';

@Component({
  selector: 'app-test',
  templateUrl: './test.component.html',
  styleUrls: ['./test.component.css']
})
export class TestComponent implements OnInit {
constructor() {}

ngAfterViewInit() {
    this.elementRef.nativeElement.querySelector('.remove')
                                  .addEventListener('click', this.click.bind(this));
  }
}

但是当我通过WebRequest调用API时,它只会返回带有消息的异常:

{
   "error": {
      "message": "Error validating access token: The session is invalid because the user logged out.",
      "type": "OAuthException",
      "code": 190,
      "error_subcode": 467,
      "fbtrace_id": "EoVgj1S1wGM"
   }
}

这是我的代码:

The remote server returned an error: Bad Request (400)

这是完整的网址:

try
      {
          var facebookBusinessAccountId =
                                ConfigurationManager.AppSettings["facebook_business_account_id"];
          facebookRestUrl += "&access_token=" + acct.AccessToken;

          facebookRestUrl = facebookRestUrl.Replace("{0}", facebookBusinessAccountId);

          var request = WebRequest.Create(facebookRestUrl);
          request.Method = method;
          request.ContentType = "application/json";

          var response = await request.GetResponseAsync();
          var reader = new StreamReader(response.GetResponseStream() ?? throw new InvalidOperationException());

          responseString = await reader.ReadToEndAsync();

          return responseString;
      }
catch (Exception e)
          {
              throw e;
          }

有人可以在Graph API Explore时帮助我获取完整的错误内容吗? 谢谢!

0 个答案:

没有答案