Welcome Developers!

in

Welcome!

in

Getting friends using Opensocial API

Last post 02-23-2009 7:09 AM by Prashant. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 01-29-2009 3:33 AM

    Getting friends using Opensocial API

    Hi  All,

    My requirement is to get a list of Myspace friends and display it on Jsp page. I refered to this link http://code.google.com/p/opensocial-java-client/source/browse/trunk/java/samples/DisplayFriends.java

      and wrote my own code as follows


    import org.opensocial.data.OpenSocialPerson;
    import org.opensocial.client.OpenSocialClient;

    import java.util.Collection;

    public class DisplayMyspaceFriends{

      public static void main(String[ args) {
        OpenSocialClient c = new OpenSocialClient("http://www.myspace.com");
            c.setProperty(OpenSocialClient.Properties.RPC_ENDPOINT, "http://api.myspace.com/v2/");
            c.setProperty(OpenSocialClient.Properties.CONSUMER_SECRET,  "----------My secret Key...........................");
        c.setProperty(OpenSocialClient.Properties.CONSUMER_KEY,  "http://www.myspace.com/-------My consumer key ID--------");
        c.setProperty(OpenSocialClient.Properties.VIEWER_ID,"--------my id-------");
           try
        {          
          // OpenSocialPerson osp = c.fetchPerson(); System.out.println("OSP name "+osp.getDisplayName());
            
          Collection<OpenSocialPerson> friends = c.fetchFriends("--------my id--------");      
          System.out.println("---------- Sidd 4");    
        
          System.out.println(friends.size() + " friends:");      
          for (OpenSocialPerson friend : friends) {     
            System.out.println("- " + friend.getDisplayName());
          }

          System.out.println("----------");

        } catch (Exception e) {
          System.out.println("Request failed:" );
          e.printStackTrace();
        }
      }

    }

     

     when i run this code i get error at line        Collection<OpenSocialPerson> friends = c.fetchFriends("--------my id--------");     

     

    error is like this


    Request failed:
    org.opensocial.client.OpenSocialRequestException: Request returned error code: 404
            at org.opensocial.client.OpenSocialBatch.getHttpResponse(Unknown Source)
            at org.opensocial.client.OpenSocialBatch.submitRpc(Unknown Source)
            at org.opensocial.client.OpenSocialBatch.send(Unknown Source)
            at org.opensocial.client.OpenSocialClient.fetchPeople(Unknown Source)
            at org.opensocial.client.OpenSocialClient.fetchPerson(Unknown Source)
            at org.opensocial.client.OpenSocialClient.fetchPerson(Unknown Source)
            at DisplayMyspaceFriends.main(DisplayMyspaceFriends.java:19)

     

    Can anyone please help me out on this ?
     

  • 02-23-2009 7:09 AM In reply to

    Re: Getting friends using Opensocial API

    Hi,

    I am finding it difficult to get my OpenSocial java application working. I have provided the stack trace below

     


    org.opensocial.client.OpenSocialRequestException: Request returned error code: 401
        at org.opensocial.client.OpenSocialBatch.getHttpResponse(Unknown Source)
        at org.opensocial.client.OpenSocialBatch.submitRest(Unknown Source)
        at org.opensocial.client.OpenSocialBatch.send(Unknown Source)
        at org.opensocial.client.OpenSocialClient.fetchPeople(Unknown Source)
        at org.opensocial.client.OpenSocialClient.fetchPerson(Unknown Source)
        at uk.co.ioko.moodmonkey.ux.pages.MySpace.setupRender(MySpace.java:34)
        at uk.co.ioko.moodmonkey.ux.pages.MySpace.setupRender(MySpace.java)

     

    Can anyone help me please?

    The code is exactly the same as provided in the link below

    http://code.google.com/p/opensocial-java-client/source/browse/#svn/trunk/java/samples

    except that it is for myspace

    Thanks in  advance.

    Regards,

    Prashant 

     

Page 1 of 1 (2 items)