Hello,

I'm trying to hook GFC/OpenSocial into my AppEngine Java website, and
I'm having trouble getting profile information to the server.  I
haven't been able to find an AppEngine example in Java that I could
understand, which speaks not to poor example code, but to the fact
that I'm a bit clueless.

Here's what I'm trying to do:  When a user logs into my website using
OpenSocial, I would like to take the display name and id and store it
on the AppEngine server.  That way I have a server-side list of all my
users.


So I have this snippet of code on my login screen:

                <!-- Load the Google AJAX API Loader -->
                <script type="text/javascript" 
src="http://www.google.com/jsapi";></
script>

                        <!-- Load the Google Friend Connect javascript library. 
-->
                        <script type="text/javascript">
                        google.load('friendconnect', '0.8');
                        </script>

                        <!-- Initialize the Google Friend Connect OpenSocial 
API. -->
                        <script type="text/javascript">
                        google.friendconnect.container.setParentUrl('/' /* 
location of
rpc_relay.html and canvas.html */);
                        google.friendconnect.container.loadOpenSocialApi({
                          site: '15569016775267298719',
                          onload: function(securityToken) {
                                if (!window.timesloaded) {
                                      window.timesloaded = 1;
                                    } else {
                                      window.timesloaded++;
                                    }
                                    if (window.timesloaded > 1) {
                                        window.top.location.href = "/auth/";
                                    }
                            }
                        });
                </script>


When the user logs in, it calls a servlet called "Login.java", which
contains the following:

public class Login extends HttpServlet {
        private HttpSession session = null;

    public void doGet(HttpServletRequest req, HttpServletResponse
resp)
                throws IOException {

        session = req.getSession(true);

                String cookieName = "fcauth" + "15569016775267298719";
                Cookie cookies [] = req.getCookies();

                Cookie authCookie = null;

                if (cookies != null) {
                        for (int i=0; i<cookies.length; i++ ) {
                                if (cookies[i].getName().equals(cookieName)) {
                                        authCookie = cookies[i];

                                        String cookieStringValue = 
authCookie.getValue();
                                        session.setAttribute("fcauth_token", 
cookieStringValue);
                                        break;
                                }
                        }
                }

                getProfileData(resp);
                resp.sendRedirect("/");
    }


The servlet finds the fcauth cookie, sends the info to a function that
gets the profile data, and the redirects back to the homepage.  The
problem lies in the getProfileData function because I don't quite
understand how to get the viewer's id number and display name.  Here
is the function where that should happen:


    public void getProfileData(HttpServletResponse resp) throws
IOException {

                Logging thisLog;

                String consumerKey = "*********************";           //  
Found this on the
GFC page
                String secretKey = "*********************";             //  
Also found this on
the GFC page
                String viewerid = ????????                                      
//  Not sure how to get the viewer's
id

                OpenSocialProvider provider = OpenSocialProvider.valueOf
("FRIENDCONNECT");
                OpenSocialClient client = new OpenSocialClient(provider);

                client.setProperty(OpenSocialClient.Property.CONSUMER_SECRET,
secretKey);
                client.setProperty(OpenSocialClient.Property.CONSUMER_KEY,
consumerKey);
                client.setProperty(OpenSocialClient.Property.VIEWER_ID, 
viewerid);

                try {
                        OpenSocialPerson viewer = client.fetchPerson();
                        thisLog = new Logging("New Member: " + 
viewer.getDisplayName() + "
" + viewer.getId());

                        //  Insert code here to make persistent on the server

                } catch (Exception e) {

                }
    }
}

I think if I could get the viewer id everything else should work.  But
it is unclear how to do that.

Thanks for any help you can give,
Chris
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"OpenSocial Application Development" group.
To post to this group, send email to opensocial-api@googlegroups.com
To unsubscribe from this group, send email to 
opensocial-api+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/opensocial-api?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to