Package facebook4j.internal.org.json

Examples of facebook4j.internal.org.json.JSONArray


    /*package*/ HttpParameter[] asHttpParameterArray() {
        List<HttpParameter> params = new ArrayList<HttpParameter>();
        params.add(new HttpParameter("question", question));
        if (options != null && options.size() != 0) {
            params.add(new HttpParameter("options", new JSONArray(options).toString()));
        }
        if (allowNewOptions != null) {
            params.add(new HttpParameter("allow_new_options", allowNewOptions));
        }
        if (published != null) {
View Full Code Here


        }
        JSONObject json = get(url)
                .asJSONObject();
        Map<String, JSONArray> result = new HashMap<String, JSONArray>();
        try {
            JSONArray jsonArray = json.getJSONArray("data");
            for (int i = 0; i < jsonArray.length(); i++) {
                JSONObject jsonObject = jsonArray.getJSONObject(i);
                String name = jsonObject.getString("name");
                JSONArray resultSets = jsonObject.getJSONArray("fql_result_set");
                result.put(name, resultSets);
            }
        } catch (JSONException jsone) {
            throw new FacebookException(jsone.getMessage(), jsone);
        }
View Full Code Here

   
    public List<TestUser> getTestUsers(String appId) throws FacebookException {
        ensureAuthorizationEnabled();
        HttpResponse res = get(conf.getRestBaseURL() + appId + "/accounts/test-users");
        try {
            JSONArray data = res.asJSONObject().getJSONArray("data");
            List<TestUser> testUsers = new ArrayList<TestUser>();
            for (int i = 0; i < data.length(); i++) {
                testUsers.add(factory.createTestUser(data.getJSONObject(i)));
            }
            return testUsers;
        } catch (JSONException jsone) {
            throw new FacebookException(jsone.getMessage(), jsone);
        }
View Full Code Here

    /* Batch Requests Methods */

    public List<BatchResponse> executeBatch(BatchRequests<BatchRequest> requests) throws FacebookException {
        ensureAuthorizationEnabled();

        JSONArray jsonArray = post(buildEndpoint(""), requests.asHttpParameterArray()).asJSONArray();
        int size = jsonArray.length();
        List<BatchResponse> result = new ArrayList<BatchResponse>(size);
        for (int i = 0; i < size; i++) {
            try {
                if (jsonArray.isNull(i)) {
                    result.add(null);
                } else {
                    JSONObject json = jsonArray.getJSONObject(i);
                    result.add(new BatchResponseImpl(json));
                }
            } catch (JSONException e) {
                throw new FacebookException(e);
            }
View Full Code Here

        for (String toUserId : toUserIds) {
            Map<String, String> map = new HashMap<String, String>(1);
            map.put("tag_uid", toUserId);
            tags.add(map);
        }
        HttpResponse res = post(buildEndpoint(photoId, "tags"), new HttpParameter[]{new HttpParameter("tags", new JSONArray(tags).toString())});
        return Boolean.valueOf(res.asString().trim());
    }
View Full Code Here

        try {
            if (conf.isJSONStoreEnabled()) {
                DataObjectFactoryUtil.clearThreadLocalMap();
            }
            JSONObject json = res.asJSONObject();
            JSONArray list = json.getJSONArray("data");
            final int size = list.length();
            ResponseList<Group> groups = new ResponseListImpl<Group>(size, json);
            for (int i = 0; i < size; i++) {
                JSONObject groupJSONObject = list.getJSONObject(i);
                Group group = new GroupJSONImpl(groupJSONObject);
                if (conf.isJSONStoreEnabled()) {
                    DataObjectFactoryUtil.registerJSONObject(group, groupJSONObject);
                }
                groups.add(group);
View Full Code Here

                JSONObject fromJSONObject = json.getJSONObject("from");
                from = new CategoryJSONImpl(fromJSONObject);
            }
            if (!json.isNull("tags")) {
                JSONObject tagsJSONObject = json.getJSONObject("tags");
                JSONArray tagsJSONArray = tagsJSONObject.getJSONArray("data");
                final int size = tagsJSONArray.length();
                tags = new ArrayList<Tag>(size);
                for (int i = 0; i < size; i++) {
                    tags.add(new TagJSONImpl(tagsJSONArray.getJSONObject(i)));
                }
            } else {
                tags = Collections.emptyList();
            }
            name = getRawString("name", json);
            description = getRawString("description", json);
            picture = getURL("picture", json);
            embedHtml = getRawString("embed_html", json);
            if (!json.isNull("format")) {
                JSONArray formatJSONArray = json.getJSONArray("format");
                final int size = formatJSONArray.length();
                format = new ArrayList<Format>(size);
                for (int i = 0; i < size; i++) {
                    format.add(new FormatJSONImpl(formatJSONArray.getJSONObject(i)));
                }
            } else {
                format = Collections.emptyList();
            }
            icon = getURL("icon", json);
            source = getURL("source", json);
            createdTime = getISO8601Datetime("created_time", json);
            updatedTime = getISO8601Datetime("updated_time", json);
            if (!json.isNull("comments")) {
                JSONObject commentsJSONObject = json.getJSONObject("comments");
                if (!commentsJSONObject.isNull("data")) {
                    JSONArray list = commentsJSONObject.getJSONArray("data");
                    final int size = list.length();
                    comments = new PagableListImpl<Comment>(size, json.getJSONObject("comments"));
                    for (int i = 0; i < size; i++) {
                        CommentJSONImpl comment = new CommentJSONImpl(list.getJSONObject(i));
                        comments.add(comment);
                    }
                } else {
                    comments = new PagableListImpl<Comment>(1, commentsJSONObject);
                }
View Full Code Here

        try {
            if (conf.isJSONStoreEnabled()) {
                DataObjectFactoryUtil.clearThreadLocalMap();
            }
            JSONObject json = res.asJSONObject();
            JSONArray list = json.getJSONArray("data");
            final int size = list.length();
            ResponseList<Video> videos = new ResponseListImpl<Video>(size, json);
            for (int i = 0; i < size; i++) {
                JSONObject videoJSONObject = list.getJSONObject(i);
                Video video = new VideoJSONImpl(videoJSONObject);
                if (conf.isJSONStoreEnabled()) {
                    DataObjectFactoryUtil.registerJSONObject(video, videoJSONObject);
                }
                videos.add(video);
View Full Code Here

    private List<String> locales;

    /*package*/TargetingJSONImpl(JSONObject json) throws FacebookException {
        try {
            if (!json.isNull("countries")) {
                JSONArray countriesJSONArray = json.getJSONArray("countries");
                countries = new ArrayList<String>(countriesJSONArray.length());
                for (int i = 0; i < countriesJSONArray.length(); i++) {
                    countries.add((String) countriesJSONArray.get(i));
                }
            } else {
                countries = new ArrayList<String>(0);
            }
            if (!json.isNull("cities")) {
                JSONArray citiesJSONArray = json.getJSONArray("cities");
                cities = new ArrayList<String>(citiesJSONArray.length());
                for (int i = 0; i < citiesJSONArray.length(); i++) {
                    cities.add((String) citiesJSONArray.get(i));
                }
            } else {
                cities = new ArrayList<String>(0);
            }
            if (!json.isNull("regions")) {
                JSONArray regionsJSONArray = json.getJSONArray("regions");
                regions = new ArrayList<String>(regionsJSONArray.length());
                for (int i = 0; i < regionsJSONArray.length(); i++) {
                    regions.add((String) regionsJSONArray.get(i));
                }
            } else {
                regions = new ArrayList<String>(0);
            }
            if (!json.isNull("locales")) {
                JSONArray localesJSONArray = json.getJSONArray("locales");
                locales = new ArrayList<String>(localesJSONArray.length());
                for (int i = 0; i < localesJSONArray.length(); i++) {
                    locales.add((String) localesJSONArray.get(i));
                }
            } else {
                locales = new ArrayList<String>(0);
            }
        } catch (JSONException jsone) {
View Full Code Here

                String language = _locale[0];
                String country = _locale[1];
                locale = new Locale(language, country);
            }
            if (!json.isNull("languages")) {
                JSONArray languagesJSONArray = json.getJSONArray("languages");
                final int size = languagesJSONArray.length();
                languages = new ArrayList<IdNameEntity>(size);
                for (int i = 0; i < size; i++) {
                    languages.add(new IdNameEntityJSONImpl(languagesJSONArray.getJSONObject(i)));
                }
            } else {
                languages = Collections.emptyList();
            }
            link = getURL("link", json);
            username = getRawString("username", json);
            thirdPartyId = getRawString("third_party_id", json);
            installed = getBoolean("installed", json);
            timezone = getDouble("timezone", json);
            updatedTime = getISO8601Datetime("updated_time", json);
            verified = getBoolean("verified", json);
            bio = getRawString("bio", json);
            birthday = getRawString("birthday", json);
            if (!json.isNull("cover")) {
                JSONObject coverJSON = json.getJSONObject("cover");
                cover = new CoverJSONImpl(coverJSON);
            }
            if (!json.isNull("education")) {
                JSONArray educationJSONArray = json.getJSONArray("education");
                final int size = educationJSONArray.length();
                education = new ArrayList<User.Education>(size);
                for (int i = 0; i < size; i++) {
                    education.add(new EducationJSONImpl(educationJSONArray.getJSONObject(i)));
                }
            } else {
                education = Collections.emptyList();
            }
            email = getRawString("email", json);
            if (!json.isNull("hometown")) {
                JSONObject hometownJSON = json.getJSONObject("hometown");
                hometown = new IdNameEntityJSONImpl(hometownJSON);
            }
            if (!json.isNull("interestedIn")) {
                JSONArray interestedInJSONArray = json.getJSONArray("interested_in");
                final int size = interestedInJSONArray.length();
                interestedIn = new ArrayList<String>(size);
                for (int i = 0; i < size; i++) {
                    interestedIn.add(interestedInJSONArray.getString(i));
                }
            } else {
                interestedIn = Collections.emptyList();
            }
            if (!json.isNull("location")) {
                JSONObject locationJSON = json.getJSONObject("location");
                location = new IdNameEntityJSONImpl(locationJSON);
            }
            political = getRawString("political", json);
            if (!json.isNull("favorite_athletes")) {
                JSONArray favoriteAthletesJSONArray = json.getJSONArray("favorite_athletes");
                final int size = favoriteAthletesJSONArray.length();
                favoriteAthletes = new ArrayList<IdNameEntity>(size);
                for (int i = 0; i < favoriteAthletesJSONArray.length(); i++) {
                    favoriteAthletes.add(new IdNameEntityJSONImpl(favoriteAthletesJSONArray.getJSONObject(i)));
                }
            } else {
                favoriteAthletes = Collections.emptyList();
            }
            if (!json.isNull("favorite_teams")) {
                JSONArray favoriteTeamsJSONArray = json.getJSONArray("favorite_teams");
                final int size = favoriteTeamsJSONArray.length();
                favoriteTeams = new ArrayList<IdNameEntity>(size);
                for (int i = 0; i < size; i++) {
                    favoriteTeams.add(new IdNameEntityJSONImpl(favoriteTeamsJSONArray.getJSONObject(i)));
                }
            } else {
                favoriteTeams = Collections.emptyList();
            }
            if (!json.isNull("picture")) {
                String pictureRawString = getRawString("picture", json);
                if (pictureRawString.startsWith("{")) {
                    JSONObject pictureJSONObject = json.getJSONObject("picture");
                    picture = new PictureJSONImpl(pictureJSONObject);
                } else {
                    picture = new PictureJSONImpl(getURL("picture", json));
                }
            }
            quotes = getRawString("quotes", json);
            relationshipStatus = getRawString("relationship_status", json);
            religion = getRawString("religion", json);
            if (!json.isNull("significant_other")) {
                JSONObject significantOtherJSONObject = json.getJSONObject("significant_other");
                significantOther = new IdNameEntityJSONImpl(significantOtherJSONObject);
            }
            if (!json.isNull("video_upload_limits")) {
                JSONObject videoUploadLimitsJSONObject = json.getJSONObject("video_upload_limits");
                videoUploadLimits = new VideoUploadLimitsJSONImpl(videoUploadLimitsJSONObject);
            }
            website = getURL("website", json);
            if (!json.isNull("work")) {
                JSONArray workJSONArray = json.getJSONArray("work");
                final int size = workJSONArray.length();
                work = new ArrayList<Work>(size);
                for (int i = 0; i < size; i++) {
                    work.add(new WorkJSONImpl(workJSONArray.getJSONObject(i)));
                }
            } else {
                work = Collections.emptyList();
            }
        } catch (JSONException jsone) {
View Full Code Here

TOP

Related Classes of facebook4j.internal.org.json.JSONArray

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.