Thanks for the quick response, Arne. I have done as you suggested, using the REST API and I was able to get the Viewer Id and Username. However, I think I am not extracting the JSON data in the most efficient manner. I'm using a URLConnection with a BufferedReader, and then splitting the string into substrings delimited by the "- character. My code follows:
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { session = req.getSession(true); String viewerId = ""; String userName = ""; Logging thisLog; 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); String restString = "http://www.google.com/friendconnect/api/ people/@me/@self?fcauth=" + cookieStringValue; String inputLine = ""; URL restUrl = new URL(restString); URLConnection restCon = restUrl.openConnection(); BufferedReader restRead = new BufferedReader( new InputStreamReader(restCon.getInputStream()));; try { inputLine = restRead.readLine(); String delim = "\""; String[] tokens = inputLine.split(delim); viewerId = tokens[5]; userName = tokens[tokens.length - 2]; thisLog = new Logging("New Member: " + userName + " " + viewerId, true); } catch (Exception e) { // } break; } } } Is there a more efficient way of extracting the JSON data? Thanks again for the help, Chris On Jul 31, 3:29 am, Arne Roomann-Kurrik <api.kur...@google.com> wrote: > Hi Chris, > > Since you're using the fcauth token, there's an implicit ID number > for the viewer - essentially, it means you can use "@me" for the value > of viewerid and a valid Person should be returned. > > ~Arne > > On Jul 30, 11:20 pm, Chris <christoph.wor...@gmail.com> wrote: > > > 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 -~----------~----~----~----~------~----~------~--~---