Giter VIP home page Giter VIP logo

Comments (23)

mattbdean avatar mattbdean commented on August 11, 2024

Can you post the HttpLogger output?

redditClient.setLoggingMode(LoggingMode.ALWAYS);

from jraw.

ccrama avatar ccrama commented on August 11, 2024

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.

mattbdean avatar mattbdean commented on August 11, 2024

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:

  1. The redirect URL you provided (http://ccrama.me) is not the same URL as in your reddit app
  2. The string you're passing into setRefreshToken() is actually the access token.
  3. The client ID is incorrect

from jraw.

ccrama avatar ccrama commented on August 11, 2024
  1. I confirmed ccrama.me is the correct URL
  2. I logged the value that I put into setRefreshToken() and confirmed it was the same one returned on UserChallenge
  3. 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.

mattbdean avatar mattbdean commented on August 11, 2024

Without the code, the only other thing I can think of is that the refresh token has been revoked.

from jraw.

ccrama avatar ccrama commented on August 11, 2024

Can you post the exact code you are using? Maybe there is a discrepancy in mine.

from jraw.

ccrama avatar ccrama commented on August 11, 2024

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.

mattbdean avatar mattbdean commented on August 11, 2024

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.

ccrama avatar ccrama commented on August 11, 2024

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.

fbis251 avatar fbis251 commented on August 11, 2024

client ID vs secret

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.

ccrama avatar ccrama commented on August 11, 2024

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.

fbis251 avatar fbis251 commented on August 11, 2024

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.

ccrama avatar ccrama commented on August 11, 2024

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.

fbis251 avatar fbis251 commented on August 11, 2024

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.

fbis251 avatar fbis251 commented on August 11, 2024

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.

ccrama avatar ccrama commented on August 11, 2024

Will test now. Thanks!

from jraw.

ccrama avatar ccrama commented on August 11, 2024

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.

fbis251 avatar fbis251 commented on August 11, 2024

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.

ccrama avatar ccrama commented on August 11, 2024

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.

ccrama avatar ccrama commented on August 11, 2024

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.

fbis251 avatar fbis251 commented on August 11, 2024

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.

ccrama avatar ccrama commented on August 11, 2024

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.

ccrama avatar ccrama commented on August 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.