How to pass Map<String, String> and Map<String, String[]> in a single open social request?

21 views
Skip to first unread message

ushap

unread,
Nov 30, 2009, 7:35:55 PM11/30/09
to opensocial-client-libraries
I need to create an activity where I need to pass open social requests
with both Map<String, String> and Map<String, String[]> data types. I
am not able to find a way to do that. I don't think I can pass them in
two separate requests. Can some one please help me with this?

Thanks!

Jason (Google)

unread,
Nov 30, 2009, 7:52:42 PM11/30/09
to opensocial-cl...@googlegroups.com
Can you explain what you're trying to do in more detail? Are you referring to an OpenSocial activity or Android activity? Can you provide some code that isn't working for you so I can have a better idea of what you're after?

- 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.



usha p

unread,
Nov 30, 2009, 8:06:44 PM11/30/09
to apij...@google.com, opensocial-cl...@googlegroups.com
Sure. I am referring to an OpenSocial activity. Here is the code I am trying to execute which is returning HTTP 500 (internal server error) from the container. Please let me know if you need more information.

Thanks,
Usha



private static void allActivityTests(OpenSocialProvider provider,
            OpenSocialClient client, Map<String, String> params) {
        try {
             String question = "question";
             String[] answers = {"a", "b", "c"};
             String description = "description";           
             String anonymous = "all";
             String hours_open= "86400";          
             responseString = client.createPoll(params, question, answers, description, anonymous, hours_open);
        } catch (org.opensocial.client.OpenSocialRequestException e) {
            System.out.println("OpenSocialRequestException thrown: "
                    + e.getMessage());
            e.printStackTrace();
        } catch (java.io.IOException e) {
            System.out.println("IOException thrown: " + e.getMessage());
            e.printStackTrace();
        }
}


public String createPoll(Map<String, String> params, String question,
            String[] answers, String description, String anonymous,
            String hours_open) throws OpenSocialRequestException, IOException {
        if (params.get("userId") == null || params.get("userId").equals("")) {
            throw new OpenSocialRequestException("Invalid request parameters");
        }

        Map<String, String> activityData = new HashMap<String, String>();
        activityData.put("question", question);
        activityData.put("question", question);
        activityData.put("description", description);
        activityData.put("anonymous", anonymous);
        activityData.put("hours_open", hours_open);
        activityData.put("type", "poll");       
        //Map<String, String[]> activityData1 = new HashMap<String, String[]>();
        //activityData1.put("answers", answers);       

        OpenSocialRequest r = OpenSocialClient.newCreateActivityRequest(params
                .get("userId"), params.get("groupId"), params.get("appId"),
                activityData, answers);
        OpenSocialBatch batch = new OpenSocialBatch();
        batch.addRequest(r, "activities");
        String s = batch.send1(this);
        return s;
    }


    public static OpenSocialRequest newCreateActivityRequest(String userId,
            String groupId, String appId, Map<String, String> data, String[] data1) {
        OpenSocialRequest r = new OpenSocialRequest("activities", "POST",
                "activities.create");
        r.addParameter(OpenSocialRequest.USER_PARAMETER, userId);
        r.addParameter(OpenSocialRequest.GROUP_PARAMETER, groupId);

        if (appId != null) {
            r.addParameter(OpenSocialRequest.APP_PARAMETER, appId);
        }

        r.addParameter("activity", new JSONObject(data).toString());       
        r.addParameter("activity", data1);
        return r;
Reply all
Reply to author
Forward
0 new messages