当前位置: 首页>>代码示例>>Java>>正文


Java JSONException类代码示例

本文整理汇总了Java中facebook4j.internal.org.json.JSONException的典型用法代码示例。如果您正苦于以下问题:Java JSONException类的具体用法?Java JSONException怎么用?Java JSONException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JSONException类属于facebook4j.internal.org.json包,在下文中一共展示了JSONException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRawFacebookCall

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
/**
 * 
 * @param url
 * @return 
 */
private JSONObject getRawFacebookCall(String url){

    try {
        Client client = Client.create();
        WebResource webResource = client
            .resource(url);
 
        ClientResponse response = webResource.accept("application/json")
            .get(ClientResponse.class);
 
        if (response.getStatus() != 200) {
                throw new RuntimeException("HTTP error code : " + response.getStatus());
        }
 
        String output = response.getEntity(String.class); 
        output = "{"+output+"}";
        output = output.replace("&expires=", ",expires=");
        return new JSONObject(output);

    } catch (RuntimeException | JSONException ex) { 
        logger.error(ex.getMessage(), ex);
    }
    return null;
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:30,代码来源:Oauth.java

示例2: getRawFacebookCall

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
private JSONObject getRawFacebookCall(String url){

        try {
            Client client = Client.create();
            WebResource webResource = client
                .resource(url);
 
            ClientResponse response = webResource.accept("application/json")
                .get(ClientResponse.class);
 
            if (response.getStatus() != 200) {
                    throw new RuntimeException("HTTP error code : " + response.getStatus());
            }
 
            String output = response.getEntity(String.class); 
            output = "{"+output+"}";
            output = output.replace("&expires=", ",expires=");
            return new JSONObject(output);

        } catch (RuntimeException | JSONException ex) { 
            ex.printStackTrace();
        }
        return null;
    }
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:25,代码来源:SignIn.java

示例3: getRawFacebookExchangeToken

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
/**
 * 
 * @return
 * @throws FacebookException
 * @throws JSONException 
 */
private AccessToken getRawFacebookExchangeToken() throws FacebookException, JSONException{
    String url = "https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token";
    String appId = configuration.getOAuthAppId(); 
    String secret = configuration.getOAuthAppSecret(); 
    String oldToken = configuration.getOAuthAccessToken(); 

    url += "&client_id="+appId+
           "&client_secret="+secret+
           "&fb_exchange_token="+oldToken;

    logger.info("entro a generar el nuevo token con el URL "+ url);
    JSONObject json = getRawFacebookCall(url);

    return new AccessToken(json.getString("access_token"), json.getLong("expires"));
    
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:23,代码来源:Worker.java

示例4: getRawFacebookCall

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
private JSONObject getRawFacebookCall(String url){
    
    logger.info("URL -> "+ url);
    
    try {
        Client client = Client.create();
        WebResource webResource = client
            .resource(url);
 
        ClientResponse response = webResource.accept("application/json")
            .get(ClientResponse.class);
 
        if (response.getStatus() != 200) {
                throw new RuntimeException("HTTP error code : " + response.getStatus());
        }
 
        String output = response.getEntity(String.class); 
        output = "{"+output+"}";
        output = output.replace("&expires=", ",expires=");
        return new JSONObject(output);

    } catch (RuntimeException | JSONException ex) { 
        logger.error(ex.getMessage(),ex);
    }
    return null;
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:27,代码来源:Worker.java

示例5: syncRawLikes

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
private void syncRawLikes(String groupId, String objectId, String toId, String type, JSONArray likes, Date createdTime, EntityManager em) throws JSONException {
    int len = likes.length();
    for(int i=0;i<len;i++){
        FacebookLikes newLike = new FacebookLikes();
        JSONObject like = likes.getJSONObject(i);
        String fromId = like.getString("id");

        try{
            newLike.setCreatedTime(createdTime);
            newLike.setFromId(fromId);
            newLike.setGroupId(groupId);
            newLike.setObjectId(objectId);
            newLike.setToId(toId);
            newLike.setType(type);
            em.merge(newLike);
        }catch(Exception ex){
            logger.error(ex.getMessage(), ex);
        }
    }
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:21,代码来源:Worker.java

示例6: syncRawMentions

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
/**
 * Sincronizar informacion acerca de los mentions que se realizan en un post
 * o comentario
 * 
 * @param groupId
 * @param objectId
 * @param fromId
 * @param type
 * @param mentions
 * @param em
 * @throws JSONException 
 */
private void syncRawMentions(String groupId, String objectId, String fromId, String type, JSONArray mentions, Date createdTime, EntityManager em) throws JSONException{

    int len = mentions.length();
    for(int i=0;i<len;i++){
        FacebookMentions newMention = new FacebookMentions();
        JSONObject mention = mentions.getJSONObject(i);
        String toId = mention.getString("id");

        try{
            newMention.setFromId(fromId);
            newMention.setObjectId(objectId);
            newMention.setToId(toId);
            newMention.setType(type);
            newMention.setGroupId(groupId);
            newMention.setCreatedTime(createdTime);
            em.merge(newMention);
        }catch(Exception ex){
            logger.error(ex.getMessage(), ex);
        }
    }
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:34,代码来源:Worker.java

示例7: syncMemberWorksInformation

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
private void syncMemberWorksInformation(JSONArray works, String uid, EntityManager em) throws JSONException, FacebookException {

        int len = works.length();
        for(int i=0;i<len;i++){
            try{
                JSONObject employer = works.getJSONObject(i).getJSONObject("employer");
                String id = employer.getString("id");
                String name = employer.getString("name");

                WorkPK newWork = new WorkPK();
                newWork.setFromId(uid);
                newWork.setWorkId(id);
                
                Work work = new Work();
                work.setWorkPK(newWork);
                work.setCreatedTime(new Date());

                em.merge(work);

                syncRawWorkInformation(id,em);
            }catch(JSONException | FacebookException ex){
                logger.error(ex.getMessage(),ex);
            }
        }
    }
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:26,代码来源:Worker.java

示例8: syncMemberEducationInformation

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
private void syncMemberEducationInformation(JSONArray educations, String uid, EntityManager em) throws JSONException, FacebookException {

        int len = educations.length();

        for(int i=0;i<len;i++){
            try{
                JSONObject education = educations.getJSONObject(i);
                JSONObject school = education.getJSONObject("school");
                String type = education.isNull("type")?"":education.getString("type");
                String institutionID = school.isNull("id")?"":school.getString("id");
                if("College".equals(type)){

                    Education newEducation = new Education();
                    newEducation.setFromId(uid);
                    newEducation.setInstitutionId(institutionID);
                    newEducation.setType(type);
                    syncRawInstitutionInformation(institutionID, em);
                    em.merge(newEducation);
                    
                }
            }catch(JSONException | FacebookException ex){
                logger.error(ex.getMessage(),ex);
            }
            
        }
    }
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:27,代码来源:Worker.java

示例9: syncRawWorkInformation

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
private void syncRawWorkInformation(String work, EntityManager em) throws FacebookException, JSONException {
   
    String url = API.WORK_INFORMATION_BY_WORK_ID.replace(":work-id", work);
    RawAPIResponse response = facebook.callGetAPI(url);
    JSONObject json = response.asJSONObject();
    
    String category = json.getString("category");
    String id = json.getString("id");
    String name = json.getString("name");
    try{
        WorkInstitution newWork = new WorkInstitution();
        newWork.setCategory(category);
        newWork.setId(id);
        newWork.setName(name);
        em.merge(newWork);
    }catch(Exception ex){
        logger.error(ex.getMessage(),ex);
    }
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:20,代码来源:Worker.java

示例10: syncLocation

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
public static void syncLocation(JSONObject location, String id, EntityManager em) throws JSONException {
    String country  = location.isNull("country")?"":location.getString("country");
    String city = location.isNull("city")?"":location.getString("city");
    String latitude = location.isNull("latitude")?"":location.getString("latitude");
    String longitude = location.isNull("longitude")?"":location.getString("longitude");
    String name = location.isNull("name")?"":location.getString("name");
    String state = location.isNull("state")?"":location.getString("state");
    String locationId = location.isNull("id")?"":location.getString("id");

    try{
        if(!"".equals(locationId)){
            Location newLocation = new Location();
            newLocation.setCity(city);
            newLocation.setCountry(country);
            newLocation.setId(locationId);
            newLocation.setLatitude(latitude);
            newLocation.setState(state);
            newLocation.setLongitude(longitude);
            newLocation.setName(name);
            em.merge(newLocation);
        }
    }catch(Exception ex){
        logger.error(ex.getMessage(),ex);
    }
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:26,代码来源:Worker.java

示例11: syncRawMentions

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
/**
 * Sincronizar información acerca de los mentions que se realizan en un post
 * o comentario
 * 
 * @deprecated 
 * @param objectId
 * @param fromId
 * @param type
 * @param mentions
 * @param em
 * @throws JSONException 
 */
private void syncRawMentions(String objectId, String fromId, String type, JSONArray mentions, EntityManager em) throws JSONException{

    int len = mentions.length();
    for(int i=0;i<len;i++){
        FacebookMentions newMention = new FacebookMentions();
        JSONObject mention = mentions.getJSONObject(i);
        
        String toId = mention.getString("id");
        newMention.setFromId(fromId);
        newMention.setObjectId(objectId);
        newMention.setToId(toId);
        newMention.setType(type);
        em.merge(newMention);

        System.out.println("(MENTION) ("+type+") objectId "+ objectId);
        System.out.println("(MENTION) ("+type+") fromId "+ fromId);
        System.out.println("(MENTION) ("+type+") toId "+ toId);
        System.out.println("(MENTION) ("+type+") type "+ type);
    }
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:33,代码来源:FacebookDao.java

示例12: syncLocation

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
private void syncLocation(JSONObject location) {
    EntityManager em = emf.createEntityManager();
    try {
        Worker.syncLocation(location, "", em);
    } catch (JSONException ex) {
        logger.error(ex.getMessage(),ex);
    }finally{
        if(em.isOpen())
            em.close();
    }
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:12,代码来源:Callback.java

示例13: getNewJSONToken

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
/**
 * 
 * @return
 * @throws JSONException 
 */
public static JSONObject getNewJSONToken() throws JSONException{
    String newToken = getNewToken(AcceptType.APPLICATION_JSON);
    newToken = "{"+newToken+"}";
    newToken = newToken.replace("&expires=",",expires=");
    logger.info(newToken);
    return new JSONObject(newToken);
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:13,代码来源:Oauth.java

示例14: syncRawMessages

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
/**
 * 
 * Sincronizar mensajes que se contienen en un post
 * 
 * @param groupId
 * @param postId
 * @param comments
 * @param em
 * @throws JSONException 
 */
private void syncRawMessages(String groupId, String postId, JSONArray comments, EntityManager em) throws JSONException, FacebookException {
    int len = comments.length();
    for(int i=0;i<len;i++){
        JSONObject message = comments.getJSONObject(i);
        boolean hasMentions = !(message.isNull("message_tags"));
        boolean hasFrom = !(message.isNull("from"));

        if(hasFrom){ // Revisar si el comentario tiene el id del creador
            FacebookComment newComment = new FacebookComment();
            Date createTime = Utils.getDateFormatted(message.getString("created_time"));
            int likesCount = Integer.parseInt(message.getString("like_count"));
            String fromId = message.getJSONObject("from").getString("id");
            String comment = message.isNull("message")?"":message.getString("message");
            String messageId = message.getString("id");

            try{
                newComment.setCreateTime(createTime);
                newComment.setLikeCount(likesCount);
                newComment.setFromId(fromId);
                newComment.setMessage(comment);
                newComment.setMessageId(messageId);
                newComment.setPostId(postId);
                newComment.setGroupId(groupId);
                em.merge(newComment);
            }catch(Exception ex){
                logger.error(ex.getMessage(), ex);
            }

            if(likesCount>0){
                syncRawMessageLikes(groupId, postId, messageId, em);
            }

            if(hasMentions){
                JSONArray mentions = message.getJSONArray("message_tags");
                syncRawMentions(groupId, messageId, fromId, "MESSAGE", mentions, createTime, em);
            }
        }
    }
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:50,代码来源:Worker.java

示例15: syncRawMessageLikes

import facebook4j.internal.org.json.JSONException; //导入依赖的package包/类
private void syncRawMessageLikes(String groupId, String postId, String messageId, EntityManager em) throws FacebookException, JSONException {
    String url = API.LIKES_IN_COMMENT.replace(":group-id",groupId);
    url = url.replace(":post-id", postId);
    url = url.replace(":comment-id", messageId);

    RawAPIResponse response = facebook.callGetAPI(url);
    JSONObject json = response.asJSONObject();

    int likesCount = json.isNull("like_count")?0:json.getInt("like_count");
    if(likesCount>0){
        String toId = json.getJSONObject("from").getString("id");
        Date createdTime = Utils.getDateFormatted(json.getString("created_time"));

        if(!json.isNull("likes")){
            JSONArray likes = json.getJSONObject("likes").getJSONArray("data");
            int len = likes.length();

            for(int i=0;i<len;i++){
                try{
                    String fromId = likes.getJSONObject(i).getString("id");
                    FacebookLikes newLike = new FacebookLikes();
                    newLike.setCreatedTime(createdTime);
                    newLike.setFromId(fromId);
                    newLike.setGroupId(groupId);
                    newLike.setObjectId(messageId);
                    newLike.setToId(toId);
                    newLike.setType("MESSAGE");
                    em.merge(newLike);
                }catch(Exception ex){
                    logger.error(ex.getMessage(), ex);
                }
            }
        }
    }
}
 
开发者ID:developersdo,项目名称:developer-influencers,代码行数:36,代码来源:Worker.java


注:本文中的facebook4j.internal.org.json.JSONException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。