X/Twitter Verification System?

Ok so this means that either your variables, BearerToken, ApiKey, or ApiKeySecret, are incorrect, or the function provided did not work.

Try placing a backslash() before any percentage signs in your heade value.

Alternatively, there is this possible solution from somebody who has already implemented something similar to what you are attempting to do: