bobolounna / restfb

Automatically exported from code.google.com/p/restfb
0 stars 0 forks source link

DefaultFacebookClient#parseAccessToken() would be nice to have #163

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Would be nice to have a method for parsing of access token. Something like this:

public static FacebookClient.AccessToken parseAccessToken(String text);

In the meantime I have to do string manipulations to get this information from 
the text provided by Facebook. Would be much more convenient to have such a 
method in the library.

BTW, the library is great!

Original issue reported on code.google.com by egor@technoparkcorp.com on 10 Nov 2011 at 8:34

GoogleCodeExporter commented 8 years ago
I think it should be a static method in FacebookClient.AccessToken class. Maybe 
it can be called just valueOf()?

Original comment by egor@technoparkcorp.com on 10 Nov 2011 at 8:35

GoogleCodeExporter commented 8 years ago
As a workaround, you should be able to say

AccessToken accessToken = new DefaultJsonMapper().toJavaObject(json, 
AccessToken.class);

...is that sufficient for what you're trying to do?

Thanks for using RestFB!

Original comment by m...@xmog.com on 10 Nov 2011 at 6:02

GoogleCodeExporter commented 8 years ago
This is what I'm doing now:

        String response = "access_token=....&expires=....";
        final String[] sectors = response.split("&");
        for (String sector : sectors) {
            final String[] pair = sector.split("=");
            if (pair.length != 2) {
                throw new IOException("invalid format");
            }
            if ("access_token".equals(pair[0])) {
                return pair[1];
            }
        }

Would be much better to have a static method for FacebookClient.AccessToken 
creation. And besides that would be nice to let DefaultFacebookClient accept an 
instance of FacebookClient.AccessToken in constructor.

Original comment by egor@technoparkcorp.com on 10 Nov 2011 at 6:15

GoogleCodeExporter commented 8 years ago
Ah, OK!  I didn't realize you meant parsing it out of a URL parameter string.  
And good idea to allow DefaultFacebookClient accept an AccessToken in a new 
ctor.  Thanks.

Original comment by m...@xmog.com on 10 Nov 2011 at 6:19

GoogleCodeExporter commented 8 years ago
It's a long time coming!

This has been implemented as the static method AccessToken.fromQueryString() 
here: 
https://github.com/revetkn/restfb/commit/a77325b0cc401d9d095c8804f545f59ed03df79
0

Thank you!

Original comment by m...@xmog.com on 2 Sep 2012 at 4:37

GoogleCodeExporter commented 8 years ago
Thanks!

Original comment by egor@technoparkcorp.com on 2 Sep 2012 at 4:39