Comments (23)
Can you post the HttpLogger output?
redditClient.setLoggingMode(LoggingMode.ALWAYS);
from jraw.
This is the output
03-22 14:53:30.732 23367-23412/me.ccrama.redditslide W/System.err﹕ java.lang.RuntimeException: Could not execute the request: HttpRequest {method='POST', url=https://www.reddit.com/api/v1/access_token, expectedMediaType=*/*, headers=User-Agent: android:me.ccrama.RedditSlide:v0.1.0 (by /u/ccrama)
03-22 14:53:30.732 23367-23412/me.ccrama.redditslide W/System.err﹕ , body=net.dean.jraw.http.RequestBody$DefaultRequestBody@301e481e}
03-22 14:53:30.738 23367-23412/me.ccrama.redditslide W/System.err﹕ at net.dean.jraw.http.RestClient.execute(RestClient.java:146)
03-22 14:53:30.738 23367-23412/me.ccrama.redditslide W/System.err﹕ at net.dean.jraw.RedditClient.execute(RedditClient.java:165)
03-22 14:53:30.738 23367-23412/me.ccrama.redditslide W/System.err﹕ at net.dean.jraw.RedditClient.execute(RedditClient.java:159)
03-22 14:53:30.739 23367-23412/me.ccrama.redditslide W/System.err﹕ at net.dean.jraw.http.oauth.OAuthHelper.refreshToken(OAuthHelper.java:288)
from jraw.
I can get an access and refresh token and use it like you described without a problem. In all likelihood, one of these is causing your problem:
- The redirect URL you provided (
http://ccrama.me
) is not the same URL as in your reddit app - The string you're passing into
setRefreshToken()
is actually the access token. - The client ID is incorrect
from jraw.
- I confirmed ccrama.me is the correct URL
- I logged the value that I put into setRefreshToken() and confirmed it was the same one returned on UserChallenge
- I confirmed the client ID is correct
Anything else that could be causing this? I can privately send you the exact code I'm running if you would like to see that.
from jraw.
Without the code, the only other thing I can think of is that the refresh token has been revoked.
from jraw.
Can you post the exact code you are using? Maybe there is a discrepancy in mine.
from jraw.
Here is the code I'm using
@Override
protected Void doInBackground(String...sub) {
try {
OAuthHelper helper = Colors.reddit.getOAuthHelper();
helper.setRefreshToken(sub[0]); //I pass the token onto this method
OAuthData data = helper.refreshToken(Credentials.installedApp("APP ACCESS TOKEN", "http://ccrama.me"));
Colors.reddit.authenticate(data); //reference to my RedditClient object
} catch (Exception e) { //If I find an exception, revert to original authentication and tell the user there was an issue with logging in
from jraw.
I'm not sure if this was a typo or not, but the app's client ID should be the first parameter in Credentials.installedApp()
, not the access token.
from jraw.
The clientID is the string reddit gives you when you registered your app, correct? I probably worded that wrong. The string from https://www.reddit.com/prefs/apps
from jraw.
Client ID is in green
secret is in red, but if the type of app you created is "installed app" then reddit will NOT provide a secret in your app preferences screen. Only the client ID will be available.
from jraw.
Ok so that is working too. Seems like I have all the parts being used correctly. Is there anything else that could be wrong?
from jraw.
You should try running your client through a proxy or enable request logging for JRAW to see the data that the network requests are sending out to make sure you have everything configured correctly.
from jraw.
I requested logging and posted it above (one of the first comments). Anything strange you see there? I have double checked everything and still cant seem to find any issue.
from jraw.
Here are JRAW's Logs from a simple JRAW Android test app:
I/JRAW ( 7574): POST https://www.reddit.com/api/v1/access_token
I/JRAW ( 7574): form-data: {grant_type=refresh_token,
I/JRAW ( 7574): refresh_token=REFRESH_TOKEN}
I/JRAW ( 7574): headers: {User-Agent: JrawTest 0.1}
I/JRAW ( 7574): basic-auth: {password=<sensitive>,
I/JRAW ( 7574): username=CLIENT_ID}
I/JRAW ( 7574): SPDY/3.1 200 OK
I/JRAW ( 7574): headers: {cache-control: no-cache,
I/JRAW ( 7574): content-type: application/json; charset=UTF-8,
... MORE HEADERS ...
I/JRAW ( 7574): response-body: {"access_token": "ACCESS_TOKEN", "token_type": "bearer", "expires_in": 36...
V/MainActivity( 7574): Authenticated
REFRESH_TOKEN is a token I had previously gotten from standard OAuth session. CLIENT_ID is the public ID for an Installed App I created using reddit's developed applications page.
The last line of the log is just an if statement checking for redditClient.isAuthenticated()
from jraw.
Here is the code I used for the request:
if (!mRefreshToken.isEmpty()) {
final Credentials credentials = Credentials.installedApp(CLIENT_ID, REDIRECT_URL);
OAuthHelper oAuthHelper = mRedditClient.getOAuthHelper();
oAuthHelper.setRefreshToken(mRefreshToken);
try {
OAuthData finalData = oAuthHelper.refreshToken(credentials);
mRedditClient.authenticate(finalData);
if (mRedditClient.isAuthenticated()) {
Log.v(LOG_TAG, "Authenticated");
}
} catch (OAuthException e) {
e.printStackTrace();
}
}
from jraw.
Will test now. Thanks!
from jraw.
Using exactly your code, I still get a bad request. I thought it might be just a bug with my current key, so I reset the app, re-authenticated, and retried. The key WAS the same, but the 400 bad request error still persists. It failes on the oAuthHelper.refreshToken() method.
from jraw.
How about creating a brand new test key?
Try your request from a different network or device.
Try to inspect the HTTP traffic with a proxy such as Burp.
At this point it doesn't look like it's an issue with the library.
from jraw.
I tried a new Client ID, new network, new auth key, and still isn't working. I honestly don't know how this issue could be occurring. Bad Request to me seems like the library is sending a bad request to Reddit, but honestly if it is working for everyone else, it must be an issue with my code. I will try to work it out tonight, and will post an update later on the status
from jraw.
I seriously have no idea what the issue is. fbis251 can you send me all the code you are using and I'll send you what I have? I might be missing something that you aren't.
from jraw.
https://gist.github.com/fbis251/5d54e95d96fbfda22a3f
I used v0.7.0.3 of JRAW and it works fine for me, just fill in the instance variables for the class and you should be good to go.
Here are the relevant sections of my build.gradle file
repositories {
jcenter()
}
dependencies {
compile 'net.dean.jraw:JRAW:0.7.0.3'
// debugging
debugCompile 'org.slf4j:slf4j-android:1.7.7'
}
from jraw.
Thank you so much. I will test this out when l get home. Pretty much everything looks the same except for the way you get your token from the we view and what you do with the cache. That might be my issue
from jraw.
ITS WORKING! I have no idea what the issue was, though. Interestingly, the authentication URL contained some illegal characters making reddit return a forbidden page,
authorizationUrl = authorizationUrl.replace("%3A%2F%2Fi", "://www");
worked fine for me. I dont know if that was my real issue, but it seemed to fix the problem on my end!
Cheers, and thanks!
from jraw.
Related Issues (20)
- Submission, get upvotes? HOT 1
- oauth version 1.0 is forbidden in reddit HOT 1
- How to use after and before HOT 1
- Possible token refresh race condition with streams HOT 1
- GET Replies to comments
- Adding Support for Community Awards HOT 1
- 404 errors being returned
- Always getting 403 Forbidden when using DefaultPaginator HOT 1
- Add a resubmit argument to SubmitReference.submit
- NullPointerException caused by outdated OkHttp HOT 1
- Extend existing model with new properties
- NullPointer EmbeddedMedia even on v1.1.0 HOT 3
- Problems setting up gradle dependencies HOT 2
- Intermittent JSON parsing exceptions HOT 2
- Support for Image Collection posts
- Upcoming OAuth2 changes
- Submission get upvote and downvote instead of score HOT 1
- Deprecation of jcenter() HOT 1
- How to get the followers count?
- Is there a way to access "Insights" on my own posts?
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jraw.