I've done the OAuth process with Stack Exchange and I have my access token.
I'm trying to perform this request https://api.stackexchange.com/docs/me-posts#order=desc&sort=activity&filter=default&site=stackoverflow&run=true
If I put my access token on this web page I get:
{
"error_id": 403,
"error_message": "`key` is not valid for passed `access_token`, application did not create token.",
"error_name": "access_denied"
}
If I perform my request in the app I get:
{
"error_id":401,
"error_message":"This method requires an access_token",
"error_name":"access_token_required"
}
I'm passing my token as:
"Authorization": "Bearer \(token)"
in my headers. But I've also tried different approach such as:
"access_token": token
"Authorization": "Basic \(token)"
But nothing to do.
But if I pass my token in this request => https://api.stackexchange.com/docs/read-access-tokens
The response is correct with user id and my scopes.
So the question is: what's wrong with that? How and where I pass my access token? I tried to delete app and get a new token.
P.S.: I'm observing the same problem in a POST request. What's wrong?
UPDATE:
Post request => https://api.stackexchange.com/docs/favorite-question
My URL => https://api.stackexchange.com/2.2/questions/< QUESTIONID >/ favorite&access_token=< ACCESSTOKEN >&key=< KEY >
UPDATE TWO:
This is my body:
{"access_token":"MYTOKEN","key":"MY KEY"}
This is my Content-Type:
request.addValue("application/x-www-form-urlencoded", forHTTPHeaderField: "Content-Type")
This is my URL:
https://api.stackexchange.com/2.2/questions/MYQUESTIONID/favorite&site=stackoverflow
site=stackoverflow&access_token=key
or something similar when you post data. access_token doesn't go in the header but as a 'formfield' in the body (or as query string parameter on the url). – rene Dec 14 '20 at 20:33id=1&filter=default&key=U4DMV*8nvpm3EOpvf69Rxw((&site=stackoverflow
– rene Dec 19 '20 at 12:57application/x-www-form-urlencoded
, e.g. what's in rene's last comment. – Glorfindel Dec 19 '20 at 13:36