magesh0407 / facebook-java-api

Automatically exported from code.google.com/p/facebook-java-api
0 stars 0 forks source link

ClassCastException for FacebookJsonRestClient.users_getLoggedInUser #307

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Instantiate a FacebookJsonRestClient as client
2. Reference client.users_getLoggedInUser
3.

What is the expected output? What do you see instead?

The expected output is for client.users_getLoggedInUser() to return a Long
integer containing the logged in users Facebook UID. Instead, I am now
getting ClassCastExceptions when users login:

java.lang.ClassCastException: java.lang.String cannot be cast to
java.lang.Number
        at
com.google.code.facebookapi.ExtensibleClient.extractLong(ExtensibleClient.java:2
281)
        at
com.google.code.facebookapi.ExtensibleClient.users_getLoggedInUser(ExtensibleCli
ent.java:721)
        at
com.google.code.facebookapi.SpecificReturnTypeAdapter.users_getLoggedInUser(Spec
ificReturnTypeAdapter.java:531)

What version of the product are you using? On what operating system?

3.0.2, Windows 7

Please provide any additional information below.

The application was working just fine a few minutes ago. I went to startup
the application and log in a user and now this error comes up. I don't know
what the problem is, I have not changed any code anywhere near the Facebook
API usage.

My code..

try {
        FacebookJsonRestClient client = new FacebookJsonRestClient(api_key,
secret_key, session_key);
//      System.err.println(client.users_getLoggedInUser());
        Long fbUID = client.users_getLoggedInUser();
        fb_id = Long.toString(fbUID);
........

I can't even print out the value being held by client.users_getLoggedInUser
in order to see what's going on, due to it having to be caught as an exception.

Original issue reported on code.google.com by XaeroDeg...@gmail.com on 7 Apr 2010 at 2:45

GoogleCodeExporter commented 8 years ago
Its happening to me to, I cant debug because its on another server, should be 
fix ASAP, its messing a lot of apps 
which uses Facebook Connect.

G.-

Original comment by gonzaloa...@gmail.com on 7 Apr 2010 at 3:21

GoogleCodeExporter commented 8 years ago
Using FacebookJaxbRestClient seems to be working. Just a FYI if you need 
something to work now ;)

G.-

Original comment by gonzaloa...@gmail.com on 7 Apr 2010 at 3:24

GoogleCodeExporter commented 8 years ago
The user id being returned from facebook is wrapped in double quotes, so the 
code is
treating it as a string instead of a number. 

Maybe facebook has changed what is returned from the request. The code looks 
like it
expects a number without double quotes around it.

Original comment by chandra....@gmail.com on 7 Apr 2010 at 4:30

GoogleCodeExporter commented 8 years ago
Chandra's explanation is correct. I have checked my past TCPdumps, it is not 
having
double quotes, but currently it does have double quotes.

Original comment by rama...@gmail.com on 7 Apr 2010 at 5:04

GoogleCodeExporter commented 8 years ago
Hi,

For thous using version 3.0.2 find the attached class, change it in the 
facebook-java-api.jar and the 
problem will be fixed.
the path for the file:
com\google\code\facebookapi\ExtensibleClient.java

The only change is in method 
    public long users_getLoggedInUser() throws FacebookException {
        if ( cacheUserId == null || cacheUserId == -1 || batchMode ) {
            String userId = callMethod(FacebookMethod.USERS_GET_LOGGED_IN_USER);
            userId = userId.replace("\"", "");
            cacheUserId = extractLong(userId);
        }
        return cacheUserId;
    }

the double quotes are replaced in the method.

Original comment by nisabek on 7 Apr 2010 at 6:37

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks nisabek, it works.

Original comment by borut.ha...@gmail.com on 7 Apr 2010 at 7:58

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Can we have the entire modified jar, thanks ;)

Original comment by bengue...@gmail.com on 7 Apr 2010 at 9:01

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago
Here is the entire fixed jar for version 3.0.2

Original comment by nisabek on 7 Apr 2010 at 9:41

Attachments:

GoogleCodeExporter commented 8 years ago
i've got this error while using the jar of nisabek

java.lang.UnsupportedClassVersionError: Bad version number in .class file

Original comment by bengue...@gmail.com on 7 Apr 2010 at 9:49

GoogleCodeExporter commented 8 years ago
This is because I have compiled my java files using jdk 1.6 and yours is 
probably 1.5 
or older. so please either use 1.6, or recompile it as mentioned earlier.

Original comment by nisabek on 7 Apr 2010 at 1:36

GoogleCodeExporter commented 8 years ago
If someone could please upload jdk 1.5 lib with the fix it would be much 
appreciated.

Original comment by serg472@gmail.com on 7 Apr 2010 at 5:50

GoogleCodeExporter commented 8 years ago
I had the same trouble. Here is the class compiled with JDK 1.5

Original comment by d.re...@googlemail.com on 8 Apr 2010 at 7:45

Attachments:

GoogleCodeExporter commented 8 years ago
http://wiki.developers.facebook.com/index.php?title=Users.getLoggedInUser&diff=5
1232&oldid=43743

hmf.. look at the small change :)

Original comment by enricoma...@gmail.com on 8 Apr 2010 at 11:00

GoogleCodeExporter commented 8 years ago
All, After i used these library (facebook-java-api-3.0.2.jar ) on above 
comment. cast 
exception problem has been solve, but i got another problem.
I always get a null return on the news feed

Original comment by rohady.w...@gmail.com on 8 Apr 2010 at 12:43

GoogleCodeExporter commented 8 years ago
Well, I'll just use the  Jaxb REST client until an OFFICIAL patch of the JAVA 
API is
 releassed. I'm only using the Facebook request on  the serverside to retrieve the
users UID, anyhow. That portion of the code is executed the same way and IS 
returning
a Long INT.

It just doesn't  make any sense why Facebook would convert types like that. They
should know that something that small can render countless application inert.

It's possible that the Facebook UID auto incrementer has reached a point where 
the ID
numbers are too large for signed or unsigned integers O_O, thus converting type 
to a
string was the only way to ensure that they could guarantee future expansion?

Original comment by XaeroDeg...@gmail.com on 8 Apr 2010 at 6:33

GoogleCodeExporter commented 8 years ago
from Users.getLoggedInUser discussion on facebook wiki:
On even further investigation, turns out this is indeed a bug and the fix 
should go
out tomorrow (April 9, 2010). The call should return an int. I changed the docs 
back.
Pete -- 563683308 15:38, 8 April 2010 (PDT) 

Seems that fix will be provided today on facebook side. Hope it will fix all 
the issues

ps: here is original link:
http://wiki.developers.facebook.com/index.php/Talk:Users.getLoggedInUser

Original comment by Artur.As...@gmail.com on 9 Apr 2010 at 9:49