最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

oauth - Why am I getting "Invalid verification code format" when requesting a long-lived token from Facebook i

programmeradmin1浏览0评论

I'm building an ASP.NET Core application that integrates with Facebook to exchange a short-lived token for a long-lived token.

When making the request, I keep receiving the following error:

StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers: { WWW-Authenticate: OAuth "Facebook Platform" "invalid_code" "Invalid verification code format." }

Code:

var httpClient = \_httpClientFactory.CreateClient();

var queryParameters = new Dictionary\<string, string\>
{
{ "client_id", clientId },
{ "redirect_uri", redirectUri },
{ "client_secret", clientSecret },
{ "state", companyId },
{ "code", authorizationCode }
};

var queryString = string.Join("&", queryParameters.Select(kvp =\>
$"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value)}"));

var urlWithParams = $"{FacebookTokenUrl}?{queryString}";

var tokenResponse = await httpClient.GetAsync(urlWithParams);

What does the error "Invalid verification code format" mean? The code is returned by FB Service while login in on front-end.

Could this issue be related to Business Verification or App Access Verification requirements in Facebook?

I'm building an ASP.NET Core application that integrates with Facebook to exchange a short-lived token for a long-lived token.

When making the request, I keep receiving the following error:

StatusCode: 400, ReasonPhrase: 'Bad Request', Version: 1.1, Content: System.Net.Http.HttpConnectionResponseContent, Headers: { WWW-Authenticate: OAuth "Facebook Platform" "invalid_code" "Invalid verification code format." }

Code:

var httpClient = \_httpClientFactory.CreateClient();

var queryParameters = new Dictionary\<string, string\>
{
{ "client_id", clientId },
{ "redirect_uri", redirectUri },
{ "client_secret", clientSecret },
{ "state", companyId },
{ "code", authorizationCode }
};

var queryString = string.Join("&", queryParameters.Select(kvp =\>
$"{Uri.EscapeDataString(kvp.Key)}={Uri.EscapeDataString(kvp.Value)}"));

var urlWithParams = $"{FacebookTokenUrl}?{queryString}";

var tokenResponse = await httpClient.GetAsync(urlWithParams);

What does the error "Invalid verification code format" mean? The code is returned by FB Service while login in on front-end.

Could this issue be related to Business Verification or App Access Verification requirements in Facebook?

Share Improve this question asked Jan 18 at 14:11 Karol TrzaskaKarol Trzaska 1 2
  • The code should be found here https://your-redirect-uri/?code=AUTHORIZATION_CODE&state=STATE. Could you share more details, so that we can verify the code, thanks. – Jason Pan Commented Jan 20 at 11:46
  • Since we don't know how you get the code, could you share your sample code about that, many thanks – Jason Pan Commented Jan 20 at 12:01
Add a comment  | 

1 Answer 1

Reset to default 0

In which phase of the OAuth protocol flow are at the stage you are mentioning? The token request you've shared doesn't specify the grant_type parameter. So perhaps this is missing, and therefore the authorization server can't handle the authorization code.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论