我正在使用Facebook Graph Api并尝试获取用户数据.我正在发送用户访问令牌,如果此令牌过期或无效Facebook返回状态代码400并且此响应:
{
"error": {
"message": "Error validating access token: The session is invalid because the user logged out.",
"type": "OAuthException"
}
}
Run Code Online (Sandbox Code Playgroud)
问题是当我使用这个C#代码时:
try {
webResponse = webRequest.GetResponse(); // in case of status code 400 .NET throws WebException here
} catch (WebException ex) {
}
Run Code Online (Sandbox Code Playgroud)
如果状态代码为400,则.NET抛出WebException,并且在异常被捕获之后我webResponse就是null这样,所以我没有机会处理它.我想这样做是为了确保问题是在过期的令牌中,而不是在其他地方.
有办法吗?
谢谢.