Cannot retrieve friends from Yahoo or Google using Java API

60 views
Skip to first unread message

Jamez

unread,
May 27, 2010, 5:58:36 AM5/27/10
to OpenSocial Client Libraries
Hi there,

I've been testing out the Opensocial API 1.0 and attempting to get a
contacts list from Yahoo and Google.
I've written the following code which acts on the OAuth redirect
returned from the third party after the user has authorised access:

OAuth3LeggedScheme scheme = (OAuth3LeggedScheme)
request.getSession().getAttribute(OAUTH_SCHEME);
Provider provider = (Provider)
request.getSession().getAttribute(OAUTH_PROVIDER);

Client client = null;

scheme.requestAccessToken(request.getParameter(OAUTH_TOKEN),request.getParameter(OAUTH_VERIFIER));

client = new Client(provider,scheme);

Response viewerResponse = client.send(PeopleService.getViewer());

List<? extends Model> items = viewerResponse.getEntries();

PrintWriter writer = new PrintWriter(response.getWriter());

String guid = items.get(0).getFieldAsString("id");

Response friendsResponse =
client.send(PeopleService.getFriends(guid));

List<Model> friends = friendsResponse.getEntries();
for(Model friend : friends) {
writer.println("Item:" + friend.toJSONString());
}

The first part that obtains the users details using the .getViewer()
method is ok however when I then attempt to obtain the user's friends
using .getFriends(guid) from Yahoo I get a 500 error and from Google I
get no items.

Can anyone help with this?

Cheers,
Jamez

Jason (Google)

unread,
Jun 1, 2010, 8:01:13 PM6/1/10
to opensocial-cl...@googlegroups.com
Hi Jamez. I'm noticing some oddness as well with my own test demo. It did work when I released it. :) I'll look into it soon and ping this thread when I have a fix.

- Jason


--
You received this message because you are subscribed to the Google Groups "OpenSocial Client Libraries" group.
To post to this group, send email to opensocial-cl...@googlegroups.com.
To unsubscribe from this group, send email to opensocial-client-l...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/opensocial-client-libraries?hl=en.


Jason (Google)

unread,
Jun 2, 2010, 6:02:36 PM6/2/10
to opensocial-cl...@googlegroups.com
Hi Jamez. I looked deeper into the problems I was running into yesterday, and it turned out that I was just signing in with the wrong account. I have an iGoogle and orkut profile set up for my gmail.com account, and when I tested the ThirdLeg demo against both, it worked just fine.

Off-hand, without running your exact setup with your consumer key and secret, I don't see why this would work for fetching the viewer but not the viewer's friends. From your syntax, it looks like you're fighting the library a little bit. Some of your code could be simplified considerably:

Response viewerResponse = client.send(PeopleService.getViewer());
Person viewer = viewerResponse.getEntry();

Response friendsResponse = client.send(PeopleService.getFriends());
List<Person> friends = friendsResponse.getEntries();
// ...

You don't have to fetch the viewer first in order to fetch the friends because the access token that you receive already corresponds to the viewer, so you should be able to call PeopleService.getFriends() without any parameters to get the viewer's friends. And you can interact with Person objects directly which are a thin wrapper on top of Models, with useful methods for getting ID, display name, and so forth.

Have you checked out the ThirdEye demo by any chance? It's included in the demos directory and is already pre-configured for Google. You can uncomment a few lines to configure it for Yahoo! instead. As I said above, it continues to work for me, and handles fetching both the viewer's profile as well as the viewer friends. Try swapping in your own credentials to see if it works for you too. Also, Yahoo! doesn't work locally, so you'll have to deploy an app if you want to see Yahoo!'s endpoints actually working. However, I don't see a 500 locally, just a 401.

- Jason

On Thu, May 27, 2010 at 2:58 AM, Jamez <james.k...@roboreus.com> wrote:
Reply all
Reply to author
Forward
0 new messages