403 on Android for Reddit API but not on browser - android

When making a request with Retrofit using an OKHttp Client with interceptors to add headers:
(Authorization: Bearer + access_token)
(User-Agent: "user_agetn_as_described_by_reddit")
Using the oauth.reddit.com/.json URL as recommended by Reddit, I get a 403. Now, when I do this same thing on Postman or something similar, I get a 200 and the expected JSON.
Is anyone aware of something related to Android or Retrofit or OKHttp that could be causing me this pain?

I was using the auth code instead of the access_token to make my requests. A mistake from my side. You should use the auth code to make a token request.

Related

OAuth 1.0 using Retrofit library in Android

I can't understand how to make OAuth 1.0 POST request using Retrofit library in Android.
This is the OAuth 1.0 Post request which I made in Postman
Help please, I can not understand how to transfer data such as consumer key, consumer secret, callbakurl to the request method, I think it is not supposed to be by annotations such as #Header or #Query. Also, I do not understand how to indicate in the request method that it is OAuth 1.0 and also that it is Authorization.
And also I get a response in the URL format. How can I get the response in the JSON format?
Thank you

OkHttp POST request set withCredentials to True?

Can't get past Django Rest Framework Token Authorization because I can't set withCredentials=true using OkHttp RequestBuilder. (I'm referring to this https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials)
In javascript using axios.post this works fine. I'm having trouble converting this post request to android using OkHttp request builder.
Request builder only seems to give setter methods for Header and Body of post Request?
Tried reading through OkHttp documentation and I've also tried to send withCredentials=True as a header
Django Rest Framework backend not recognizing the token and not resolving the bearer token to a user.
If no class authenticates, request.user will be set to an instance > of django.contrib.auth.models.AnonymousUser, and request.auth > will be set to None.
I'm going to assume here that withCredentials is a query parameter.
Appending ?withCredentials=true. to the end of the URL will probably get things going for you.
An example in full might look like https://www.example.com?withCredentials=true.
With multiple parameters, it may look like https://www.example.com?withCredentials=true&otherParam=Stuff.

Retrofit modifying server response received

I am using retrofit on newsApi. I am trying to hit endpoint
https://newsapi.org/v2/sources?apiKey=xxxxx
In case of wrong api key server is returning:
{"status":"error","code":"apiKeyInvalid","message":"Your API key is invalid or incorrect. Check your key, or go to https://newsapi.org to create a free API key."}
and in case of no api key server is returning:
{“status”:“error”,“code”:“apiKeyMissing”,“message”:“Your API key is missing. Append this to the URL with the apiKey param, or use the x-api-key HTTP header.”}
but in my application retrofit is returning following for both the cases:
Response{protocol=http/1.1, code=401, message=Unauthorized, url=https://newsapi.org/v2/sources}
just the url is changed for both cases but message and code is same.
Why is retrofit modifying server response and how can I get the original server message or response?
Thanks in advance.
Not having an api key makes you unauthorized, so Retrofit is not wrong to access the error body check out this previous answer

How to use session and redirect in Volley library

I can request to my API by this python code snippet (use requests python):
session = requests.session()
r=session.post(url,data=post_data, auth=(username , passwd))
Server will use this session and redirect my request to another get request then return the json response successfully.
I want to implement this api request on Android using Volley library. I have figured all day, and there is no luck. I can request an GET api successfully, but POST.
I have tried all answer on this question on SO
It seem I cannot create a session for Volley can use it.
Does anyone have experience in using session/cookie for Volley library?

Google Reader API request token, get 400:Bad Request

this Android code worked fine before, but i'm having problems for some reason. here is the request i'm trying to make:
https://www.google.com/reader/api/0/token
i'm getting 400:Bad Request as a response, and i'm not sure why. isn't this the correct URL for requesting a token? the auth token is being passed as a header in all requests now, and i can request feed list, and it works just fine, so there's nothing wrong with the auth code. what gives?
in addition, i can request a token in a normal browser, like Chrome, and get a token as a response body. so the request itself is not the problem. i just can't figure out what is wrong with my requests in code...
the answer is to use http rather than https. if anyone else is having trouble getting tokens from the unofficial google reader api, check whether you are using secure http or not.

Categories

Resources