Subversion Repositories SmartDukaan

Rev

Rev 20180 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package in.shop2020.serving.utils;

import java.util.HashMap;
import java.util.Map;
import java.util.ResourceBundle;

import org.json.JSONObject;

import in.shop2020.serving.controllers.ProceedToPayController;

public class FacebookUtility {

        private String FBURL = "https://graph.facebook.com/debug_token";
        private String FBGETDETAILS = "https://graph.facebook.com/me";
         private static final ResourceBundle resource = ResourceBundle.getBundle(FacebookUtility.class.getName());
            private static final String APPID = resource.getString("facebookAppId");
            
        //private final static String APPID = "273800242824516";
        private final static String APPSECRET = resource.getString("facebookAppSecret");

        public JSONObject verifyFbToken(String accessToken, String reqEmail, boolean isFbUser, String fbId) {
                boolean result = false;
                Utils util = new Utils();
                JSONObject resp = new JSONObject();
                try {

                        Map<String, String> paramsMap = new HashMap<String, String>();
                        paramsMap.put("access_token", accessToken);
                        paramsMap.put("fields", "id,name,email,permissions");
                        String response = util.callRestApi(FBGETDETAILS, Utils.METHOD_GET, paramsMap, null);
                        JSONObject json = new JSONObject(response);

                        // check both emails
                        reqEmail = reqEmail.replace("@", "\u0040");
                        result = reqEmail.equalsIgnoreCase(json.getString("email"));
                        resp.put("id", json.getString("id"));
                        if (isFbUser) {
                                // match the facebookid with fbId
                                result = fbId.equals(json.getString("id"));

                        }

                        resp.put("status", result);

                        System.out.println(resp.toString());
                } catch (Exception e) {
                        e.printStackTrace();
                }

                return resp;

        }

}