Package facebook4j

Examples of facebook4j.Facebook


public class LogoutServlet extends HttpServlet {
    private static final long serialVersionUID = 5357658337449255998L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {     
        Facebook facebook = (Facebook) request.getSession().getAttribute("facebook");
        String accessToken = "";
        try {
          accessToken = facebook.getOAuthAccessToken().getToken();
        } catch (Exception e) {
            throw new ServletException(e);
        }
        request.getSession().invalidate();
View Full Code Here


    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String message = request.getParameter("message");
        Facebook facebook = (Facebook) request.getSession().getAttribute("facebook");
        try {
            facebook.postStatusMessage(message);
        } catch (FacebookException e) {
            throw new ServletException(e);
        }
        response.sendRedirect(request.getContextPath()+ "/");
    }
View Full Code Here

public class CallbackServlet extends HttpServlet {
    private static final long serialVersionUID = 6305643034487441839L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Facebook facebook = (Facebook) request.getSession().getAttribute("facebook");
        String oauthCode = request.getParameter("code");
        try {
            facebook.getOAuthAccessToken(oauthCode);
        } catch (FacebookException e) {
            throw new ServletException(e);
        }
        response.sendRedirect(request.getContextPath() + "/");
    }
View Full Code Here

public class SignInServlet extends HttpServlet {
    private static final long serialVersionUID = -7453606094644144082L;

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Facebook facebook = new FacebookFactory().getInstance();
        request.getSession().setAttribute("facebook", facebook);
        StringBuffer callbackURL = request.getRequestURL();
        int index = callbackURL.lastIndexOf("/");
        callbackURL.replace(index, callbackURL.length(), "").append("/callback");
        response.sendRedirect(facebook.getOAuthAuthorizationURL(callbackURL.toString()));
    }
View Full Code Here

public class AddFacebookAccountController extends BaseController {

    @Override
    protected Navigation execute(UserModel loginUserModel) throws Exception {

        Facebook facebook = sessionScope("facebook");
        String oauthCode = asString("code");

        System.out.println("oauthCode: " + oauthCode);

        try {
            // アクセストークンの取得
            AccessToken accessToken = facebook.getOAuthAccessToken(oauthCode);
            String tokenString = accessToken.getToken();

            // アクセスを2ヶ月有効トークンに変更
            Map<String, String> params = new HashMap<String, String>();
            params.put("client_id", Constants.FACEBOOK_APP_API_KEY);
            params.put("client_secret", Constants.FACEBOOK_APP_API_SECRET);
            params.put("grant_type", "fb_exchange_token");
            params.put("fb_exchange_token", tokenString);

            RawAPIResponse apiResponse = facebook.callGetAPI("/oauth/access_token", params);
            String response = apiResponse.asString();
            AccessToken newAccessToken = new AccessToken(response);
            String newToken = newAccessToken.getToken();

            if(newToken != null) {
                User facebookUser = facebook.getMe();

                loginUserModel.setFacebookAccessToken(new Text(newToken));
                loginUserModel.setFacebookAccountName(facebookUser.getName());

                // ユーザーグループを変更
View Full Code Here

public class OAuthController extends BaseController {

    @Override
    protected Navigation execute(UserModel loginUserModel) throws Exception {

        Facebook facebook = new FacebookFactory().getInstance();
        facebook.setOAuthAppId(Constants.FACEBOOK_APP_API_KEY, Constants.FACEBOOK_APP_API_SECRET);
        facebook.setOAuthPermissions(Constants.FACEBOOK_APP_API_PERMISSIONS);
        sessionScope("facebook", facebook);


        return redirect(facebook.getOAuthAuthorizationURL(Constants.FACEBOOK_APP_OAUTH_CALLBACK));

    }
View Full Code Here

            if(activityModel.getVerb().getCategory().equals(Constants.GOOGLE_ACTIVITY_VERB_TYPE_SHARE)) {
                return null;
            }

            // Facebook オブジェクトの取得
            Facebook facebook = getFaceBookObject(userModel);


            // メッセージの作成
            String msg = getMessage(activityModel);

            // POST
            if(!activityModel.isAttachmentsFlg()) {
                // 添付がない場合
                if(msg != null) {
                    facebook.postStatusMessage(msg);
                }

            }else if(activityModel.getAttachmentsType().getCategory().equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_ARTICLE)) {
                // リンク付き投稿の場合
                URL attachmentsUrl = new URL(activityModel.getAttachmentsUrlString());

                if(msg == null) {
                    facebook.postLink(attachmentsUrl);

                }else {
                    facebook.postLink(attachmentsUrl, msg);
                }

            }else if(activityModel.getAttachmentsType() != null
                    && (activityModel.getAttachmentsType().getCategory().equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_PHOTO)
                    || activityModel.getAttachmentsType().getCategory().equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_ALBUM))
                      && activityModel.getVerb().getCategory().equals(Constants.GOOGLE_ACTIVITY_VERB_TYPE_POST)) {
                // 写真付き投稿の場合

                Media media = getPhotoMedia(activityModel.getAttachmentsImageUrlString());
                PhotoUpdate photoUpdate = new PhotoUpdate(media);

                if(msg != null) {
                    photoUpdate.setMessage(msg);
                }

                facebook.postPhoto(photoUpdate);


//            }else if(activityModel.getAttachmentsType() != null
//                    &activityModel.getAttachmentsType().getCategory().equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_ALBUM)
//                      && activityModel.getVerb().getCategory().equals(Constants.GOOGLE_ACTIVITY_VERB_TYPE_POST)) {
//                // アルバム投稿の場合
//
//                AlbumUpdate albumUpdate = new AlbumUpdate("PluCial");
//
//                // メッセージを追加
//                if(msg != null) {
//                    albumUpdate.setMessage(msg);
//                }
//
//                // アルバムを作成
//                String albumId = facebook.createAlbum(albumUpdate);
//
//                // アルバムの写真リストを取得
//                List<AlbumModel> albmList = activityModel.getAlbumModelListRef().getModelList();
//
//                // アルバムに写真の追加
//                for(AlbumModel albumModel: albmList) {
//                    Media media = getPhotoMedia(Utils.changeAlbumUrl(albumModel));
//                    facebook.addAlbumPhoto(albumId, media);
//                }


            }else if(activityModel.getAttachmentsType() != null
                    && activityModel.getAttachmentsType().getCategory().equals(Constants.GOOGLE_ACTIVITY_ATTACHMENTS_TYPE_VIDEO)) {
                // 動画の場合
                URL embedUrl = new URL(activityModel.getEmbedUrlString());

                if(msg == null) {
                    facebook.postLink(embedUrl);

                }else {
                    facebook.postLink(embedUrl, msg);
                }
            }


        }catch(Exception e) {
View Full Code Here

     * @param msg
     * @return
     */
    private Facebook getFaceBookObject(UserModel userModel) throws Exception {

        Facebook facebook = new FacebookFactory().getInstance();
        facebook.setOAuthAppId(Constants.FACEBOOK_APP_API_KEY, Constants.FACEBOOK_APP_API_SECRET);
        facebook.setOAuthPermissions(Constants.FACEBOOK_APP_API_PERMISSIONS);
        facebook.setOAuthAccessToken(new AccessToken(userModel.getFacebookAccessTokenString()));

        return facebook;
    }
View Full Code Here

            if (endpoint.getConfiguration().getJsonStoreEnabled() == null
                || !endpoint.getConfiguration().getJsonStoreEnabled()) {
                result = invokeMethod(endpoint.getConfiguration().getFacebook(),
                    method, args);
            } else {
                final Facebook facebook = endpoint.getConfiguration().getFacebook();
                synchronized (facebook) {
                    result = invokeMethod(facebook, method, args);
                    rawJSON = DataObjectFactory.getRawJSON(result);
                }
            }
View Full Code Here

                    if (endpoint.getConfiguration().getJsonStoreEnabled() == null
                        || !endpoint.getConfiguration().getJsonStoreEnabled()) {
                        result = FacebookMethodsTypeHelper.invokeMethod(
                            endpoint.getConfiguration().getFacebook(), method, properties);
                    } else {
                        final Facebook facebook = endpoint.getConfiguration().getFacebook();
                        // lock out the underlying Facebook object from other threads
                        synchronized (facebook) {
                            result = FacebookMethodsTypeHelper.invokeMethod(
                                facebook, method, properties);
                            rawJSON = DataObjectFactory.getRawJSON(result);
View Full Code Here

TOP

Related Classes of facebook4j.Facebook

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.