moreiracruz / facebook-java-api

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

Getting incorrect signature on easy friends_get() example #203

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Hi, I am currently developing a desktop app with a Facebook support. Now at 
first I am trying to 
get the Facebook friends_get() example to work.

What steps will reproduce the problem?
1. My example code as follows:

            FacebookJsonRestClient client = new FacebookJsonRestClient(API_KEY, SECRET);

            String token = client.auth_createToken();

            String url = "http://www.facebook.com/login.php?api_key=" + API_KEY + "&v=1.0" 
+ "&auth_token=" + token;

            Runtime.getRuntime().exec("open " + url);

            System.out.println("log in to facebook and press enter.");
            System.in.read();

            String session = client.auth_getSession(token);
            System.out.println("Session key is " + session);

            Long userId = client.users_getLoggedInUser();
            System.out.println("Fetching friends for user " + userId);

            client.friends_get();
            FriendsGetResponse response = (FriendsGetResponse) client.getResponsePOJO();

            List<Long> friends = response.getUid();

            client.users_getInfo(friends, EnumSet.of(ProfileField.NAME));

            UsersGetInfoResponse userResponse = (UsersGetInfoResponse) 
client.getResponsePOJO();

            List<User> users = userResponse.getUser();
            for (User user : users) {
                System.out.println(user.getName());
            }

2. I signed my app as a desktop app in the Facebook developers site.

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

I expect a list of ID numbers of the users friends. I get (The output of my 
test app):

log in to facebook and press enter.

Session key is 2.MzaXTYy6sftJjnvDtHIWZw__.86400.1241467200-1539614153
Fetching friends for user 1539614153
com.google.code.facebookapi.FacebookException: Incorrect signature
    at 
com.google.code.facebookapi.FacebookJsonRestClient.parseCallResult(FacebookJsonR
estClient.ja
va:354)
    at com.google.code.facebookapi.ExtensibleClient.callMethod(ExtensibleClient.java:535)
    at com.google.code.facebookapi.ExtensibleClient.callMethod(ExtensibleClient.java:458)
    at com.google.code.facebookapi.ExtensibleClient.friends_get(ExtensibleClient.java:817)
    at 
com.google.code.facebookapi.FacebookJsonRestClient.friends_get(FacebookJsonRestC
lient.java:6
43)
    at FacebookGetFriends.main(FacebookGetFriends.java:40)

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

facebook-java-api 2.1.1 on Mac OSX 10.5

Please provide any additional information below.

I don't know where the problem is. Both keys are the right ones, I even got a 
session key from 
Facebook. How comes, that I have an incorrect signature? I am a bit desperate, 
because I was 
looking for that issue all day and I just could not find an answer. I would be 
very glad if 
somebody could help.

Andrea

Original issue reported on code.google.com by brackka...@googlemail.com on 3 May 2009 at 7:35

GoogleCodeExporter commented 8 years ago
Please read the FAQ Wiki page, specifically the link to this document:
http://code.google.com/p/facebook-java-api/wiki/DesktopMode

It explains web vs. desktop mode. What's yours set to?

Original comment by david.j....@googlemail.com on 6 May 2009 at 6:27

GoogleCodeExporter commented 8 years ago
Hey,

the app is set to desktop on the Facebook Developer Site, although it keeps 
telling me via isDesktop() that it is 
not in desktop mode. Guess thats the problem.

I read the Wiki FAQ before, but I still don't get the right order how things 
have to happen in the 
authentication process. Unfortunately I could not find any proper examples, 
because things changed with 
2.1.1.

Please give me just a few hints, maybe steps on how to authenticate a desktop 
app. I will find out the rest. 
Thank you very much in advance.

Andrea

Original comment by brackka...@googlemail.com on 6 May 2009 at 10:08

GoogleCodeExporter commented 8 years ago
Okay,  I guess I made it over the authentication process now. I do not get an 
incorrect signature error anymore and it seems like it is trying 
to fetch users without complaining. Although the result of the fetch remains 
empty and it still gives me a false when asking isDesktop().

My code:
FacebookJsonRestClient client = new FacebookJsonRestClient(API_KEY, SECRET_KEY);
String token = client.auth_createToken();
String url = "http://www.facebook.com/login.php?api_key=" + API_KEY + 
"&version=1.0" + "&auth_token=" + token;
Runtime.getRuntime().exec("open " + url); // OS X only!
System.out.println("log in to facebook and press enter.");
System.in.read();
String session = client.auth_getSession(token, true);
String sessionSecret = client.getSessionSecret();
String cacheSessionKey = client.getCacheSessionKey();
client = new FacebookJsonRestClient(API_KEY, sessionSecret, cacheSessionKey);
Boolean isDesktop = client.isDesktop();
Long userId = client.users_getLoggedInUser();
client.friends_get();
FriendsGetResponse response = (FriendsGetResponse) client.getResponsePOJO();

Original comment by brackka...@googlemail.com on 7 May 2009 at 1:40

GoogleCodeExporter commented 8 years ago
with your updated examples and your comment in the discussion forums 
(http://groups.google.com/group/facebook-java/browse_thread/thread/a1c04d77faa61
8f4#) i finally got my 
code working. thank you very much, that helped a lot! I know the worth of good 
documentation, although I 
am a programmer myself and i know about the lack of time and interest in that. 
I hope you can create a good 
and productive community around your project and care about a better 
documentation this way, because you 
did a great job so far on the code side of things.

You may close this issue now.

Thank you for the good work!
Andrea

Original comment by brackka...@googlemail.com on 11 May 2009 at 10:58

GoogleCodeExporter commented 8 years ago
Hi Andrea,

Could you share with me the code to fix the problem. I used the same code as 
you and
got the same problem "Invalid signature"

private void showFriends(FacebookJsonRestClient client, Long userID) {
try {
    FriendsGetResponse response = (FriendsGetResponse)client.friends_get(userID);
    List<Long> friends = response.getUid();

    // Go fetch the information for the user list of user ids
    client.users_getInfo(friends, EnumSet.of(ProfileField.NAME));
    UsersGetInfoResponse userResponse = (UsersGetInfoResponse) client.getResponsePOJO();  
    // Print out the user information
    List<User> users = userResponse.getUser();
    for (User user : users) {
        System.out.println(user.getName());
    }
} catch (FacebookException e) {
    e.printStackTrace();
}
}

Thanks
Thai

Original comment by tha...@gmail.com on 16 May 2009 at 2:31

GoogleCodeExporter commented 8 years ago
Hey Thai,

my code (without session secret method)

    FacebookJaxbRestClient client = new FacebookJaxbRestClient(API_KEY, SECRET_KEY,SESSION);

            Long userId = client.users_getLoggedInUser();

            FriendsGetResponse response = (FriendsGetResponse) client.friends_get();
            System.out.println(response);

            List<Long> friends = response.getUid();

            List<ProfileField> profileFields = new ArrayList<ProfileField>();
            profileFields.add(ProfileField.NAME);
            profileFields.add(ProfileField.STATUS);
            UsersGetInfoResponse infoResponse = (UsersGetInfoResponse) client.users_getInfo(friends, 
profileFields);

            List<User> users = infoResponse.getUser();
            for (User user : users) 
            {
                System.out.println(user.getName());
                System.out.println(user.getStatus().getMessage());
            }

hope it helps! if not feel free to contact me

Original comment by brackka...@googlemail.com on 17 May 2009 at 11:02

GoogleCodeExporter commented 8 years ago
Hi, im new to facebook development..
@brackkatze:
im using your code but failed in: 

Long userId = client.users_getLoggedInUser();

that returns:

com.google.code.facebookapi.FacebookException: Incorrect signature.

what's wrong with it?
im using java facebook api by the way..
thanks a lot..

Original comment by hari.fir...@gmail.com on 17 Jun 2009 at 1:38

GoogleCodeExporter commented 8 years ago
java facebook api 2.1.1 on Win 7, i mean..

thanks

Original comment by hari.fir...@gmail.com on 17 Jun 2009 at 1:41

GoogleCodeExporter commented 8 years ago
Kindly check issue#203 also and provide suggestions... 

Regards
Sagar

Original comment by sagarhas...@gmail.com on 23 Sep 2009 at 7:17

GoogleCodeExporter commented 8 years ago
Hello Andrea,

I'm executing your code but I'm using 3.0.2 api. I'm getting errors on the 
following
lines:
FriendsGetResponse response = (FriendsGetResponse) client.friends_get();
UsersGetInfoResponse infoResponse = (UsersGetInfoResponse)
client.users_getInfo(friends, profileFields);

It says:
java.lang.RuntimeException: Uncompilable source code - inconvertible types
found   : org.json.JSONArray
required: com.google.code.facebookapi.schema.FriendsGetResponse

Please help me out!!

Thanks for your help!

Ayesha

Original comment by ayeshasi...@gmail.com on 18 Feb 2010 at 6:22