| 20180 |
aman.kumar |
1 |
package in.shop2020.serving.utils;
|
|
|
2 |
|
|
|
3 |
import java.util.HashMap;
|
|
|
4 |
import java.util.Map;
|
|
|
5 |
|
|
|
6 |
import org.json.JSONObject;
|
|
|
7 |
|
|
|
8 |
public class FacebookUtility {
|
|
|
9 |
|
|
|
10 |
private String FBURL = "https://graph.facebook.com/debug_token";
|
|
|
11 |
private String FBGETDETAILS = "https://graph.facebook.com/me";
|
|
|
12 |
private final static String APPID = "716370691734306";
|
|
|
13 |
private final static String APPSECRET = "a467cf8754b7b8e30315aa7269f40e85";
|
|
|
14 |
|
|
|
15 |
public JSONObject verifyFbToken(String accessToken, String reqEmail, boolean isFbUser, String fbId) {
|
|
|
16 |
boolean result = false;
|
|
|
17 |
Utils util = new Utils();
|
|
|
18 |
JSONObject resp = new JSONObject();
|
|
|
19 |
try {
|
|
|
20 |
|
|
|
21 |
Map<String, String> paramsMap = new HashMap<String, String>();
|
|
|
22 |
paramsMap.put("access_token", accessToken);
|
|
|
23 |
paramsMap.put("fields", "id,name,email,permissions");
|
|
|
24 |
String response = util.callRestApi(FBGETDETAILS, Utils.METHOD_GET, paramsMap, null);
|
|
|
25 |
JSONObject json = new JSONObject(response);
|
|
|
26 |
|
|
|
27 |
// check both emails
|
|
|
28 |
reqEmail = reqEmail.replace("@", "\u0040");
|
|
|
29 |
result = reqEmail.equalsIgnoreCase(json.getString("email"));
|
|
|
30 |
resp.put("id", json.getString("id"));
|
|
|
31 |
if (isFbUser) {
|
|
|
32 |
// match the facebookid with fbId
|
|
|
33 |
result = fbId.equals(json.getString("id"));
|
|
|
34 |
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
resp.put("status", result);
|
|
|
38 |
|
|
|
39 |
System.out.println(resp.toString());
|
|
|
40 |
} catch (Exception e) {
|
|
|
41 |
e.printStackTrace();
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
return resp;
|
|
|
45 |
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
}
|